Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Printing Numbers using Thousand Separators

June 30, 2023 — Gregg Szumowski

You can use a pipe to awk to output numbers with thousands separators (commas). For Example, here’s how you can total the 5th column of the ls -l command and print it with thousands separators:

$ ls -l | awk '{total = total + $5}END{print total}' | LC_ALL=en_US.UTF-8 awk '{printf("%'"'"'d\n", $0) }'
21,387

This can be adapted to other commands as necessary.

Tags: cli, bash, awk, motd