Skip to content

Instantly share code, notes, and snippets.

@dutc
Last active August 29, 2015 14:00
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 dutc/d13b59f40639f6f8a0a6 to your computer and use it in GitHub Desktop.
Save dutc/d13b59f40639f6f8a0a6 to your computer and use it in GitHub Desktop.
cut -d ';' -f 2- ~/.zsh_history | \
tr '|;' '\n' | \
FS=' ' awk '{ print $1 }' | \
cut -d '/' -f -1 | \
awk '/^[a-zA-Z]/ { cmds[$0] += 1 } END { for (cmd in cmds) print cmd, cmds[cmd] }' | \
awk '{ first = tolower(substr($1,1,1)); count = int($2); if (max[first] < count) { max[first] = count; cmds[first] = $1 } } END { for (f in cmds) print f, cmds[f], max[f] }' | \
sort
@dutc
Copy link
Author

dutc commented May 1, 2014

Gives:

a acpi 1085
b bash 300
c cd 13901
d df 469
e echo 563
f find 830
g grep 2095
h head 239
i if 140
j jobs 56
k killall 194
l ls 21854
m mplayer 3752
n nm 73
o objdump 164
p python 2201
q qalc 758
r rm 1522
s sudo 1648
t tmux 1555
u unzip 97
v vim 4007
w watch 303
x xargs 570

@AnneTheAgile
Copy link

A trivial change, but to make it easy :). Paste this is you don't have ZShell;

cut -d ';' -f 2- ~/.bash_history | \
tr '|;' '\n' | \
FS=' ' awk '{ print $1 }' | \
cut -d '/' -f -1 | \
awk '/^[a-zA-Z]/ { cmds[$0] += 1 } END { for (cmd in cmds) print cmd, cmds[cmd] }' | \
awk '{ first = tolower(substr($1,1,1)); count = int($2); if (max[first] < count) { max[first] = count; cmds[first] = $1 } } END { for (f in cmds) print f, cmds[f], max[f] }' | \
sort

Thank you James!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment