-
-
Save killerbees19/a64b7213c34aec423ef374cea305f51f 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