Shell – printf, awk … How to format a number with space to the thousands

awkbcprintfsedshell

Is there a simple way to separate a very large number per thousands with printf, awk, sed ?

So 10000000000000 become 10 000 000 000 000

Thanks

Best Answer

A simple combination of sed and rev could be employed -

echo  "I have 10000013984 oranges" | rev | sed "s/[0-9][0-9][0-9]/& /g" | rev 

first rev is required to replace number from right to left , and the second one for bringing back the original string.

Related Question