I have a file ( input.txt) with a structure like this:
abc 1
bcd a
cde 1
def 4
efg a
fgh 3
I want to remove duplicates in column 2 to only have unique rows in this column (no matter what is in column 1). But the selected row must be selected aleatory . The output could be, for example:
bcd a
cde 1
def 4
fgh 3
I tried to create a file listing the duplicates (using awk '{print $2}' input.txt | sort | uniq -D | uniq), but then I managed to delete all of them using awk '!A[$2]++'instead of accidentally storing one of the duplicates.
Svalf source
share