We have the following text file:
172.55.34.48 172.55.33.95 172.55.32.163 172.55.34.48 172.55.32.163 172.55.33.95 What we need to do is to swap the two columns if the first column is found to contain a value already encountered previously on that column. For each such value (IP addresses in this case), the max occurence is two.
In the above example, we need to swap 172.55.33.95 with 172.55.32.163 as 172.55.32.163 was already found on the previous line.
I tried
awk 'prev && ($1 != prev) {print seen[prev]} {seen[$1] = $0; prev = $1} END {print seen[$1]}' /tmp/new.txt but this helps to remove lines where the column 1 entry was already found before.
0.0.0.0 1.1.1.1a duplicate of1.1.1.1 0.0.0.0? What if there's more than one duplicate, what should happen to those lines?172.55.32.163and172.55.33.95is172.55.33.95then considered to have appeared in the first column or not?