history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } splice((sort {$b <=> $a} keys %a),0,10) }'
Oops, just realised it should be sorted by the value and not the key so...
history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } splice((sort {$a{$b} <=> $a{$a}} keys %a),0,10) }'
Also noticed that splice() isn't setting wantarray() so you'll need to use direct indexing which is probably easier to write too...
history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } (sort {$a{$b} <=> $a{$a}} (keys %a))[0..9] }'
history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } splice((sort {$b <=> $a} keys %a),0,10) }'
Oops, just realised it should be sorted by the value and not the key so...
history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } splice((sort {$a{$b} <=> $a{$a}} keys %a),0,10) }'
Also noticed that splice() isn't setting wantarray() so you'll need to use direct indexing which is probably easier to write too...
history | perl -ne '/^\s*\d+\s+(\w+)/ && $a{$1}++; END { map { print "$a{$_} $_\n" } (sort {$a{$b} <=> $a{$a}} (keys %a))[0..9] }'