The file content is as follows:
333379266 834640619 88
333379280 834640621 99
333379280 834640621 66
333376672 857526666 99
333376672 857526666 78
333376672 857526666 62
The first two columns may be duplicate, and I want to output the first two columns and the corresponding max value of the third column.In this case,The result file should be as follows:
333379266 834640619 88
333379280 834640621 99
333376672 857526666 99
My attemp is:
awk '{d[$1" "$2]=$3;if ($3>=d[$1" "$2]){num[$1" "$2]=$3} else{num[$1" "$2]=d[$1" "$2]} }END{for(i in num) print i,num[i]}'
But it does not work,because $3>=d[$1" "$2]
is always right , the value of num is always $3
, and awk
reads the file line by line,so the value of num
is always the last one,not the max one.
I'll be appreciated if anyone can give me the solution.Thanks in advance.