compare fields in a file with duplicate records

Hi:

I've been searching the net but didnt find a clue. I have a file in which, for some records, some fields coincide. I want to compare one (or more) of the dissimilar fields and retain the one record that fulfills a certain condition. For example, on this file:

99  TR   1991  5  06   60.000  -19.995  277
64  TR   1991  5  06   60.000  -19.995  275
60  TA   1990  7  17   60.000  -19.998  300
89  TA   1990  7  17   60.000  -19.998  277
46  CU   1992  8  29   61.020  -16.880  009
35  CU   1992  8  29   61.020  -16.880  003

retain the record with greater value on the last field for each duplicate:

99  TR   1991  5  06   60.000  -19.995  277
60  TA   1990  7  17   60.000  -19.998  300
46  CU   1992  8  29   61.020  -16.880  009

while sending the unwanted data to another file:

64  TR   1991  5  06   60.000  -19.995  275
89  TA   1990  7  17   60.000  -19.998  277
35  CU   1992  8  29   61.020  -16.880  003

Thanks, in advance.

r.-

You can use awk for this.

$ awk '{if(arr[$2]=="")arr[$2]=$0; else{split(arr[$2],tmp);if($8>tmp[8]) sub(/tmp[8]$/,arr[$2],$8);}}END{for(item in arr)  print arr[item]}' infile
46  CU   1992  8  29   61.020  -16.880  009
60  TA   1990  7  17   60.000  -19.998  300
99  TR   1991  5  06   60.000  -19.995  277