Skip to content

Instantly share code, notes, and snippets.

@cghiban
Created April 19, 2018 16:55
Show Gist options
  • Save cghiban/9db82d6b8933788fad3de518f98ad43c to your computer and use it in GitHub Desktop.
Save cghiban/9db82d6b8933788fad3de518f98ad43c to your computer and use it in GitHub Desktop.
convers long numbers into readable ones
#!/bin/bash
# usage:
# $ echo 1234567|./nicenumber.sh
# 1,234,567
# $ find .|wc -l|./nicenumber.sh
# 426,704
while read line; do
# run the number thru the comma mill
echo $line \
|sed '/....$/ s/^\(.*\)\(...\)$/\1,\2/;
/....,...$/ s/^\(.*\)\(...,...\)$/\1,\2/;
/....,...,...$/ s/^\(.*\)\(...,...,...\)$/\1,\2/;
/....,...,...,...$/ s/^\(.*\)\(...,...,...,...\)$/\1,\2/;
/....,...,...,...,...$/ s/^\(.*\)\(...,...,...,...,...\)$/\1,\2/'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment