Created
March 16, 2015 09:33
-
-
Save unfo/86621fa7bc7b87cd99f8 to your computer and use it in GitHub Desktop.
simple awk script for drawing ascii graphs
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
# Should be used with | sort | uniq -c | |
# Example input: | |
# 2 0 | |
# 3 1 | |
# 46 2 | |
# 6 3 | |
# 20 4 | |
# 115 5 | |
function draw_graph() { | |
awk 'BEGIN { highest= -1 } { sum += $1; items += 1 ; if ($1 > highest) { highest = $1 } ; values[$2] = $1; } END { print highest; for (val in values) { print values[val] " " val } }' | \ | |
awk '{ if (NF == 1) { highest = $1 } else { printf("%d ", $2); for (i = 0; i <= int(80 * ($1 / highest)); i++) { printf("#") } ; printf(" (%d)\n", $1) } }' | |
} |
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
$ cat triple | awk -F';' '$5 ~ /[0-9]/ { print $5 }' | sort | uniq -c | draw_graph | |
0 ## (6) | |
1 ### (9) | |
2 ################################# (138) | |
3 ##### (18) | |
4 ############## (60) | |
5 ################################################################################# (345) | |
$ cat original | awk -F';' '$5 ~ /[0-9]/ { print $5 }' | sort | uniq -c | draw_graph | |
0 ## (2) | |
1 ### (3) | |
2 ################################# (46) | |
3 ##### (6) | |
4 ############## (20) | |
5 ################################################################################# (115) | |
$ wc -l original triple | |
193 original | |
579 triple | |
$ cat original | awk -F';' '$5 ~ /[0-9]/ { print $5 }' | sort | uniq -c | |
2 0 | |
3 1 | |
46 2 | |
6 3 | |
20 4 | |
115 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hourly log hits