-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathhistogram-by-date
executable file
·37 lines (35 loc) · 1.18 KB
/
histogram-by-date
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
36
37
#!/bin/sh
set -euf -o pipefail
##
# Histogram by date, on the command line
#
# Credit: Small labs Inc.
# See http://www.smallmeans.com/notes/shell-history/
#
# How it works:
#
# * grep ... Select lines that start with YYYYMMDD (optional - or /)
# * sed ... Delete everything after the date
# * 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:
#
# cat log | histogram-by-date
#
# Contact: Joel Parker Henderson ([email protected])
# License: GPL
# Updated: 2015-01-25
##
grep '^ *[0-9][0-9][0-9][0-9][-/]\?[0-9][0-9][-/]\?[0-9][0-9]\b' | sed 's/^ *\([0-9][0-9][0-9][0-9][-/]\?[0-9][0-9][-/]\?[0-9][0-9]\)\b.*/\1/' | histogram