You're viewing a comment by Ilia and its responses.

October 13, 2012, 05:58

1. It looks weird, that you are taking the second column of history output with cut, instead of doing that inside of awk block. (in your "top 10" example)

2. I think that awk is an overkill for the common task of counting the number of entries. The same can be done a la "| sort | uniq -c | sort -nr". I think that this code snippet is much easier to remember than the line of awk code, even though it performs worse.

Comment Responses

October 13, 2012, 15:38

1. I love when each command does just one thing, and I love to pipe things together.

I could have written it as a Perl one-liner:

history | perl -lne 's/\d+//;s/^\s+//;s/\s\s/ /; $count{$_}++; END { print "$count{$_} $_" for (sort { $count{$a} <= $count{$b} } keys %count )[0..10] }'

2. Good example of combining commands together.

lava Permalink
November 04, 2012, 20:14

Also, it would be an overkill to use
history | sort | uniq -c | sort -rn

because, as you stated in the article, history is printing .bash_history to the screen. For most users it would be better to run:
$ sort .bash_history | uniq -c | sort -rn

because this will exclude one pipe.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "server_334": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.