简体   繁体   中英

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 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.

uniq removes adjacent duplicates. If you want to omit duplicates that are not adjacent, you'll have to sort the data first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM