Last active
October 31, 2024 17:27
-
-
Save fsteffenhagen/e09b827430956d7f1de35140111e14c4 to your computer and use it in GitHub Desktop.
sum human readable file sizes with numfmt and awk
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
# Input: list of rows with format: "<filesize> filename", e.g. | |
# filesizes.txt | |
####################### | |
# 1000K file1.txt | |
# 200M file2.txt | |
# 2G file3.txt | |
# | |
# Output: | |
cat filesizes.txt | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}' | |
2358222848 | |
cat filesizes.txt | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}' | numfmt --to=iec | |
2.2G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on MacOS
Then enjoy
numfmt
Man page