Skip to content
Advertisement

AWK remove duplicate line based on two conditions

I am trying to remove duplicates based on the value of the 2nd field. The lower value of the 2nd field should be retained, any line with repeated 1st field and higher 2nd field should be removed.

This is an example of my raw data:

JavaScript

Here is how it should be:

JavaScript

So far, based on this post: I came up with this script:

JavaScript

But it returns with no results.

I am still learning how to use awk, particularly the associate array.

Any help is welcome. Thanks in advance!

Advertisement

Answer

You can use this awk:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement