Skip to content

Instantly share code, notes, and snippets.

@jan-swiecki
Last active February 23, 2023 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-swiecki/bb3f78c3a9d5601fe8313cdc2c909426 to your computer and use it in GitHub Desktop.
Save jan-swiecki/bb3f78c3a9d5601fe8313cdc2c909426 to your computer and use it in GitHub Desktop.
hist.awk
#!/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