How can I find the unique lines and remove all duplicates from a file? My input file is
1 1 2 3 5 5 7 7
I would like the result to be:
While sort takes O(n log(n)) time, I prefer using
sort
awk '!seen[$0]++'
awk '!seen[$0]++' is an abbreviation for awk '!seen[$0]++ {print}', print line(=$0) if seen[$0] is not zero. It take more space but only O(n) time.
awk '!seen[$0]++ {print}'
seen[$0]