1

I have a file like below which I have sorted based on the username field.

1234    200   suresh
5678    150   murali
8543    200   sanjith
5678    100   suresh
1456    400  murali

I am trying to remove the rows which have the lowest score for the same usernames. So I want to have the output using Shell Script.

1234    200   suresh
5678    400   murali
8543    200   sanjith
4
  • Hi there, please format your examples and state what you have tried. And a pro-tip "info coreutils" shows you kinda-man-pages for some really helpful commands. Commented Feb 11, 2016 at 6:32
  • why does 5678 400 murali in your output. Shouldn't it be 1456 400 murali? Commented Feb 11, 2016 at 6:39
  • Sorry it should be 1456 400 murali. Commented Feb 11, 2016 at 8:28
  • Possible duplicate of stackoverflow.com/questions/22822465/… Commented Feb 11, 2016 at 9:57

1 Answer 1

1

You can use awk's associative array:

awk '$2>m[$3]{m[$3]=$2; r[$3]=$0} END{for (i in r) print r[i]}' file
1456    400  murali
1234    200   suresh
8543    200   sanjith
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.