I have a file like below which I have sorted based on the username field. UserID score UserName1234    200   Jack5678    150   Jill8543    200   Jill 5678    100   JohnI am trying to remove the rows which have the lowest score for the same usernames. So, I want to have the output as,UserID score UserName1234    200   Jack8543    200   Jill 5678    100   John
awk remove the rows based on another column value
sed;awk
The simplest approach would be to sort on the score field instead:$ sort -nk2 file | awk '{k[$NF]=$0} END{for (i in k){print k[i]}}'UserID score UserName8543    200   Jill 1234    200   Jack5678    100   JohnOr, in perl:sort -nk2 file | perl -ane '$k{$F[$#F]}=$_; END{print $k{$_} for keys(%k)}'The -a flag for perl turns on auto splitting, basically it will behave like awk, and split each line on white space, saving the fields in the array @F. The -n means process the input file line, by line. $F[$#F] is the last element of @F, so the last field: the username. $k{$F[$#F]}=$_; saves each line in the hash %k where the keys are the usernames, overwriting whatever was there before. Since we first sort the file, this means that $k{username} will be the highest score for that username's entry. At the end, we print each line saved in %k. 