Sort with Awk, sed ....

I want to print out the lines that have the max value in column 3. and count the occurrence of column 1; if there are more than one occurrences, line with highest column 2 value will be printed.
I have this data:

input:

AV 234 25 
AV 256 76
AS 421 34
AV 124 76
BD 136 71
BD 241 76
AW 111 76
BD 241 76
BD 255 76

Output:

AV 256 76 2
BD 255 76 3
AW 111 76 1

---------- Post updated at 06:35 AM ---------- Previous update was at 05:14 AM ----------

Can someone please help with this?

Hi, what have you tried so far?

I know the first step is to sort out the Max value on column 3, i just dont know how to go about it.

Once you know that maximum, you could then reparse the input. I came up with this:

awk 'NR==FNR&&$3>m{m=$3;next} $3==m&&$2>A[$1]{A[$1]=$2; B[$1]++; C[$1]=$0} END{for(i in A)print C, B}' infile infile
sort -nrk3 infile | awk 'NR==1{m=$3;a[$1]++;b[$1]=(b[$1])?b[$1]:$0;next}$3==m{a[$1]++;b[$1]=(b[$1])?b[$1]:$0}END{for (i in a){print b,a}}'

i'm not getting result

What system are you using?

1 Like

SunOS 5.10 Generic_127127-11 sun4u sparc SUNW,SPARC-Enterprise

Use nawk or /usr/xpg4/bin/awk instead of awk.

1 Like

it worked! thanks

$DLC/bin/rfutil db1 -C aimage list
i am using this command and gettin d output below..
Extent: 1
Status: Empty
Type: Fixed Length
Path: /home/mralbu/ai_dir/db1.a1
Size: 8184
Used: 0
Start: N/A
Seqno: 0

Extent: 2
Status: Full
Type: Fixed Length
Path: /home/mralbu/ai_dir/db1.a2
Size: 8184
Used: 1
Start: Mon Nov 8 14:21:51 2010
Seqno: 54

Extent: 3
Status: Busy
Type: Fixed Length
Path: /home/mralbu/ai_dir/db1.a3
Size: 8184
Used: 1
Start: Mon Nov 8 14:21:55 2010
Seqno: 55

Extent: 4
Status: Empty
Type: Variable Length
Path: /home/mralbu/ai_dir/db1.a4
Size: 120
Used: 0
Start: N/A
Seqno: 0

i want to get the Seqno for evry particular db1 after image n assign it as SEQNC..

i used this command below... n its workin..
SEQNC=`$DLC/bin/rfutil $DB -C aimage scan -a $EXT_NAME |grep number |tail -1 |awk '{print $6}'`

bt for that i need to keep my databse shut..
wat do i do...

help asap..