Prueba Prueba
Prueba Prueba

Reputation: 13

Difference between using the uniq command with sort or without it in linux

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

Answers (1)

Mureinik
Mureinik

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

Related Questions