user1214325
user1214325

Reputation: 1

Shell Script to read the file and find the highest count

I am new to shell scripting.I need to write a script to read each line from the file. Let's say each line has ID like A, B, C, D etc. But there can be duplicate IDs also. Two or more lines can have same ID. I need to find out the highest number for each ID. i.e if there are 3 IDs as "A". then I need to find out which is highest among those 3. and so on for ID "B", "C",,,and so on....

Thank you...

Upvotes: 0

Views: 254

Answers (1)

kev
kev

Reputation: 161864

Sample data:

A 3
B 2
C 4
A 1
B 9
A 6

Run command:

$ sort -k1,1 -k2,2nr data.txt | sort -u -k1,1

Output:

A 6
B 9
C 4

Upvotes: 1

Related Questions