Finding the highest value(in negative)

Hi all,

I have a simple problem. I have given an example of the problem below.

There are 4 space-delimited columns.

2655    96    IA    -0.8179 
2655    96    IA    -0.9144 
2655    96    CPU    -0.4275
2655    96    RMA    -0.3407 
2655    96    IA    -0.9373
2655    96    eugene    -0.8338 
2655    96    CPU    -0.9469 

Result should look like the following, where the forth column has only the highest values for the particular item in column 3. Generally I could use awk for this purpose, but I am confused as how to deal with the negative values.

2655    96    IA    -0.8179 
2655    96    CPU    -0.4275 
2655    96    RMA    -0.3407 
2655    96    eugene    -0.8338

Please help. Thanks.

---------- Post updated at 12:55 AM ---------- Previous update was at 12:52 AM ----------

a solution in awk will be like:

awk '{if ($4 > a[$1" "$2" "$3])a[$1" "$2" "$3]=$4}END{for (i in a) print i, a}' file

but this does not work for the negative values

awk '
!a[$1" "$2" "$3] || $4 > a[$1" "$2" "$3] { a[$1" "$2" "$3] = $4 } 
END { for (i in a) print i, a }
' INPUTFILE
1 Like

woo hoo!!! such a quick reply and works too :slight_smile: