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.