-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathhistogram
executable file
·35 lines (33 loc) · 1.02 KB
/
histogram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
set -euf -o pipefail
##
# Histogram on the command line
#
# Credit: Small labs Inc.
# See http://www.smallmeans.com/notes/shell-history/
#
# How it works:
#
# * sort Sort, so that similar commands come in groups
# * uniq -c Count subsequent items (-c prepends count)
# * sort -rn Sort in descending order (reverse)
# * head -20 Get the 20 most frequent commands
#
# * awk '!max{max=$1;}{ Everything is nice and in order:
# r=""; run thru the items, format, pad, print
# i=s=60*$1/max;
# while(i-->0){
# r=r"#"; string concatenation, AWK-style
# }
# printf "%15s %5d %s %s",$2,$1,r,"\n";
# }'
#
# Example:
#
# history | awk '{print $2}' | histogram
#
# Contact: Joel Parker Henderson ([email protected])
# License: GPL
# Updated: 2015-01-25
##
sort | uniq -c | sort -rn | awk '!max{max=$1;}{r="";i=s=60*$1/max;while(i-->0)r=r"#";printf "%15s %5d %s %s",$2,$1,r,"\n";}'