Add commas to numbers in Unix, need to change 1234567 as 1,234,567
Is it possible in sed or awk? If so please give some sample.
$ LC_NUMERIC=en_US
$ printf "%'.f" 1234567
1,234,567
Courtesy of jim mcnamara: Locale determines what happens with the thousands separator.
$ export LC_NUMERIC="en_US.UTF-8"
$ printf "%'f\n" 1234567.777
1,234,567.777000
$ export LC_NUMERIC=C
$ printf "%'f\n" 1234567.777
1234567.777000
This last one has no commas. Your result had no commas. Do you see why now? Locale LC_NUMERIC setting is your answer. The C locale does not have a thousands separator. I'm guessing your locale does not either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With