Computing.Net > Forums > Programming > akw unique query

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

akw unique query

Reply to Message Icon

Name: user57
Date: September 11, 2008 at 01:55:32 Pacific
OS: AIX 5.3
CPU/Ram: 4/32
Product: p550
Comment:

Looking for an AWK solution to pull out unique entries on $1. If multiple occurences exist the rule is to examine the second field and print the line with the greatest numeric, as illustrated by the sample data below:

Input
aa:10:123
aa:18:123
aa:11:123
aa:10:123
bb:50:10
cc:11:00
bb:49:00

Output
aa:18:123
bb:50:10
cc:11:00



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: September 14, 2008 at 19:45:14 Pacific
Reply:


awk -F":" '{
if ( arr[$1] < $2 ) { arr[$1]=$2 }
else { arr[$1] }
}
END{
for(i in arr) { print arr[i],i }
}' file


0

Response Number 2
Name: user57
Date: September 15, 2008 at 01:33:17 Pacific
Reply:

That's great ghostdog.

Many thanks for your assistance.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


C Structure shell script code for fil...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: akw unique query

Need SQL query help. www.computing.net/answers/programming/need-sql-query-help/13097.html

SQL Server unique id field www.computing.net/answers/programming/sql-server-unique-id-field/8808.html

SQL Queries in MS Access www.computing.net/answers/programming/sql-queries-in-ms-access/6911.html