Help: Find line where column has max vlaue

Hi all,

Ive searched the forum but with no luck...

I have a file:

ID Name Val
1 bob 45
2 joe 89
3 sue 11
4 steve 89
...
etc

I want to find a way to print lines which have the largest value in the 'Val' column...i say lines as you may have one or more with the same value.

Output should be (if one or more same highest - otherwise only one row):
2 joe 89
4 steve 89

You can do somthing like that (assume no header in input file) :

sort -k3nr input_file| awk '
NR==1 { max = $3 }
$3<max { exit }
1
'

Jean-Pierre.

 awk 'NR==1{next} $3==max{s=s"\n"$0} $3>max{max=$3;s=$0} END{print s}' infile

I dont get anything?

What if the input file has comma separated values?

Works fine on my AIX box :

$ cat muay.sh
sort -k3nr muay.txt| awk '
NR==1 { max = $3 }
$3<max { exit }
1
'
$ cat muay.txt
1 bob 45
2 joe 89
3 sue 11
4 steve 33
5 averell 89
6 willian 89
7 lucky 9
8 jack 89
$ ./muay.sh
2 joe 89
5 averell 89
6 willian 89
8 jack 89
$ 

If the delimiter is comma :

sort -t, -k3nr muay.txt| awk -F, '
NR==1 { max = $3 }
$3<max { exit }
1
'

Jean-Pierre.

Comma-delimited version:

awk -F, 'NR==1{next} $3==max{s=s"\n"$0} $3>max{max=$3;s=$0} END{print s}' infile
sort +2 -nr a.txt | awk 'NR==1{print;max=$3;}NR>1{if($3==max){print;}}'