Print whole line with highest value from one column

Hi, I have a little issue right now.
I have a file with 4 columns

test0000002,10030010330,c_,218
test0000002,10030010330,d_,202
test0000002,10030010330,b_,193
test0000002,10030010020,c_,178
test0000002,10030010020,b_,170
test0000002,10030010330,a_,166
test0000002,10030010020,a_,151
test0000002,10030010020,d_,150
test0000002,10030070050,c_,119
test0000002,10030070050,b_,99
test0000002,10030070050,d_,79
test0000002,10030070050,a_,56
test0000002,10030010390,c_,55
test0000002,10030010390,b_,44
test0000002,10030010380,d_,41
test0000002,10030010380,a_,37
test0000002,10030010390,d_,35
test0000002,10030010380,c_,33
test0000002,10030010390,a_,31
test0000002,10030010320,c_,30
test0000002,10030010320,b_,27
test0000002,10030010380,b_,26
test0000002,10030010320,a_,23
test0000002,10030010320,d_,22
test0000002,10030010010,a_,6

and I want the highest value from 4th column sorted from 2nd column.

test0000002,10030010330,c_,218 
test0000002,10030010020,c_,178 
test0000002,10030010330,a_,166 
test0000002,10030010020,a_,151 
test0000002,10030070050,c_,119 
test0000002,10030010390,c_,55 
test0000002,10030010380,d_,41 
test0000002,10030010320,c_,30 
test0000002,10030010390,a_,31 
test0000002,10030010380,c_,33 
test0000002,10030010390,d_,35 
test0000002,10030010320,a_,23 
test0000002,10030010380,b_,26 
test0000002,10030010010,a_,6

You can use sort to sort for more than one key, in your case for second column first and for fourth column (in reverse order) second:

sort -t, -k2,2 -k4,4rn /path/to/your/file

Every line with a new value in the second field will be one of the lines you are interested in.

I hope this helps.

bakunin

Double post. Please continue at: https://www.unix.com/shell-programming-and-scripting/276764-print-whole-line-highest-value-one-column.html