Last active
February 23, 2023 08:15
-
-
Save jan-swiecki/bb3f78c3a9d5601fe8313cdc2c909426 to your computer and use it in GitHub Desktop.
hist.awk
This file contains hidden or 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/awk -f | |
# Original script: https://stackoverflow.com/a/39637429/1637178 | |
# License: https://creativecommons.org/licenses/by-sa/3.0/ | |
# This one works with integers | |
# Example: | |
# $ du -s some_folder/* | awk '{ print $1; }' > sizes | |
# $ ./hist.awk sizes | |
# | |
# Change bin_width, bar_scale_down and %5d accordingly | |
BEGIN{ | |
bin_width=1000; | |
bar_scale_down=100; | |
# substr trick source: https://stackoverflow.com/a/68796165/1637178 | |
# Basically repeat("=", n) = substr("========================", 1, n) | |
base_bar="=========================================================================================================================================" | |
} | |
{ | |
bin=int(($1-0.0001)/bin_width); | |
if( bin in hist){ | |
hist[bin]+=1 | |
}else{ | |
hist[bin]=1 | |
} | |
} | |
END{ | |
for (h in hist) | |
printf " * > %5d -> [%5d] %s \n", h*bin_width, hist[h], substr(base_bar, 1, hist[h]/bar_scale_down) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment