I know how to remove adjacent duplicates in vi. Or
:%!uniq
or
:g/^\(.*\)$\n\1$/d).
But I have a file that has data in random order, and there are several duplicate lines that are scattered throughout the file. How to remove all these duplicates without disturbing the row order? Should the first unique row be kept, and the next (or all the rest) duplicate should be deleted?
eg. cat file1
Here looking at you, Kid.
Casablanca
Here looking at you, Kid.
Go ahead, make my day.
Dirty Harry
sleep 5
Go ahead, make my day.
Yippee-ki-yay
The conclusion should be:
Here looking at you, Kid.
Casablanca
Go ahead, make my day.
Dirty Harry
sleep 5
Yippee-ki-yay
source
share