Saturday, April 27, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 6002  / 2 Years ago, tue, december 14, 2021, 3:11:31

I have a file that needs sorting in a specific way but I can't figure out how to do it.



I've tried the following command but it doesn't give me what I want:



sort -t" " -k1,1 Original_File | uniq -d > Desired_Output


Original_File:



User1 US
User1 NG
User2 US
User3 US
User4 US
User4 EN
User5 US


Desired_Output:



User1 US
User1 NG
User4 US
User4 EN

More From » text-processing

 Answers
2

You can extract the first column, pick up the duplicates, and grep them back from the file again:



cut -f1 -d' ' Original_File | sort | uniq -d | grep -wFf- Original_File

[#23467] Tuesday, December 14, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
strhen

Total Points: 27
Total Questions: 111
Total Answers: 103

Location: Angola
Member since Tue, Apr 25, 2023
1 Year ago
;