In python re.sub(r(?<=.)(?=(?:...)+$), ,, stroke ) To split a number by triplets, e.g.: echo 123456789 | python -c 'import sys;import re; print re.sub(r(?<=.)(?=(?:...)+$), ,,  sys.stdin.read());' 123,456,789How to do the same with bash/awk?
Add thousands separator in a number
bash;shell script;awk;string
With sed:$ echo 123456789 | sed 's/\([[:digit:]]\{3\}\)\([[:digit:]]\{3\}\)\([[:digit:]]\{3\}\)/\1,\2,\3/g'123,456,789(Note that this only works for exactly 9 digits!)or this with sed:$ echo 123456789 | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'123,456,789With printf:$ LC_NUMERIC=en_US printf %'.f\n 123456789123,456,789