Hacker News new | ask | show | jobs
by anon_mouse 2970 days ago
I can copy/paste your statement and it works..

but when I try to save it as an alias method.. I keep getting error:

awk: cmd. line:1: {CMD[]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;} awk: cmd. line:1: ^ syntax error awk: cmd. line:1: error: invalid subscript expression

I thought I would just escape the double quotes ", and things would work. :/ Any ideas?

2 comments

  alias mostused='history | awk '\''{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}'\'' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10'
That's not how shell quoting works. I don't want to explain the mistake and the fix.

Use a shell function instead of an alias, that's the better tool here.