Issue
Let's say I have a two-column file with this content:
1 4
1 11
4 5
5 11
I want to delete all the lines if the number (from 1st or 2nd column) is found in next lines whether it is in the first or 2nd column.
So I should have something like this as a result:
1 4
5 11
- The second line in the initial file i.e. (1 11) is deleted because '1' was already in the first line.
- The third line (4 5) is deleted because '4' was already in the first line.
- But the fourth line (5 11) is not deleted because the third line (4 5) has been deleted just before.
I've already tried using awk or sort but didn't manage to obtain the expected result. Is there anything to do this ?
Thanks in advance.
Solution
Following awk
may help you on same.
awk '{for(i=1;i<=NF;i++){if($i in a){next};a[$i]}} 1' Input_file
Answered By - RavinderSingh13