Dec 23, 2009

Format Numbers to be Comma Separated

I have a number 1234567890, and I want to insert a comma at the gap of three digits like this:1,234,567,890

If this is the problem running in your head then the following one liner will be helpful to you.

$ echo "1234567890" | sed -e ':a' -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'

No comments: