user3188922
user3188922

Reputation: 349

Sorting based on first column and highest number in third column

I have a text file that needs to be sorted, my goal is to only keep the longest sequences in each of my modules. My text file looks like this:

1  abc  35
1  def  90
1  ghi  100
2  jui   500
3  yui   500
3  iop   300

My goal is to sort unique modules (first column) by keeping highest number from column 3, just like this:

1  ghi 100
2 jui   500
3 yui  500

So far I checked the sort options but without success, I guess awk could also do it! I tried:

sort -u -k1,1 Black.txt | sort -k3n,3

Any help would be much appreciated!

Upvotes: 0

Views: 127

Answers (1)

Ashoka Lella
Ashoka Lella

Reputation: 6729

You sort them based on the third column first and later unique them by first column.

sort -r -k 1 -k3n,3 Black.txt|sort -u -k1,1

output

1  ghi  100
2  jui   500
3  yui   500

Upvotes: 1

Related Questions