Top ten occurrences with perl one-liner

Very nice perl one-liner using map, sort and array range to show top ten occurrences

Taken from Tech@Sakana blog

perl -ane '$c{$F[0]}++; END {print map {$_ . "\t->\t" . $c{$_} . "\n"} (sort {$c{$b} <=> $c{$a}} keys %c)[0..9]}' filename

Same thing can be achieved by:

sort filename | uniq -c | sort -nr | head

But the perl one-liner demonstrates the nice combination of sort and map.

Avatar
Alper Yilmaz
Assist.Prof.Dr. Alper YILMAZ

My research interests include genome grammar and NGS analysis.

Related

comments powered by Disqus