$ perl -ne'$x{$_}++}END{print"$x{$_}\t$_"for(sort{$x{$b}<=>$x{$a}}keys%x)[0..4]' test.txt 5 many hardships 2 a million dollars 2 love life 2 apple pie 1 you attempt things