Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Last active December 10, 2015 09:39
Show Gist options
  • Save avdgaag/4415801 to your computer and use it in GitHub Desktop.
Save avdgaag/4415801 to your computer and use it in GitHub Desktop.
Shell one-liner to create a histogram from a log file.
export COL=$COLUMNS; awk -F '[ ()]|ms' '/\[CatalogItem\] Retrieved/ { c[int($8 / $6 / 100) * 100 + 50] += $6 } END { for(l in c) { print l, c[l] } }' production.log | awk 'BEGIN { max = 0 } { if($2 > max) max = $2; c[$1] = $2 } END { for(l in c) { printf("%5d %d\n", l, c[l] / max * (ENVIRON["COL"] - 7)) } }' | awk '{ r = ""; s = $2; while(s-- > 0) { r = r "#" }; printf("%6d %s\n", $1, r); }' | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment