Last active
May 25, 2023 00:26
-
-
Save jflopezfernandez/36ab29c9d8ccb4578d06b7af46094ad2 to your computer and use it in GitHub Desktop.
This script takes every integer passed to it and prints it to standard output as an integer formatted according to US English convention. That is, numbers with more than three digits are printed with every three digits from the right separated by a comma.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# | |
# This script takes every integer passed to it and prints it to standard output | |
# as an integer formatted according to US English convention. That is, numbers | |
# with more than three digits are printed with every three digits from the right | |
# separated by a comma. | |
# | |
# This command was run via the command-line, not as an actual shell script. This | |
# gist is just a way for me to remember how I did it. | |
# | |
# The memory-numbers.txt file contains the following data. | |
# | |
# 128974848 | |
# 2147483648 | |
# 128974848 | |
# 1073741824 | |
# 3145728000 | |
# 4724465664 | |
# 128974848 | |
# 4116774912 | |
# 6291456000 | |
# | |
# This command results in the following output. | |
# | |
# 128,974,848 | |
# 2,147,483,648 | |
# 128,974,848 | |
# 1,073,741,824 | |
# 3,145,728,000 | |
# 4,724,465,664 | |
# 128,974,848 | |
# 4,116,774,912 | |
# 6,291,456,000 | |
# | |
# It could also be used as follows: | |
# | |
# echo -e "82771968\n3145728000" | perl -nE 'chomp;my $value = $_;while ($value =~ s/(\d+)(\d{3})/$1,$2/) {} print "$value\n";' | |
# | |
# This example would result in the following output: | |
# | |
# 82,771,968 | |
# 3,145,728,000 | |
# | |
perl -nE 'chomp;my $value = $_;while ($value =~ s/(\d+)(\d{3})/$1,$2/) {} print "$value\n";' memory-numbers.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment