Reputation: 13
When I use uniq -u data.txt
lists the whole file and when I use sort data.txt | uniq -u
it omits repeated lines. Why does this happen?
uniq
man says that -u, --unique only prints unique lines. I don't understand why I need to use pipe to get correct output.
Upvotes: 1
Views: 1684
Reputation: 311308
uniq
removes adjacent duplicates. If you want to omit duplicates that are not adjacent, you'll have to sort the data first.
Upvotes: 2