tag 23268 notabug close 23268 thanks Hello,
On 04/11/2016 06:49 AM, 126 wrote:
hello, Gentleman when I use sort and uniq, and input like this below, I got wrong output:
[...]
"|sort -u
[...]
no result when I use `uniq -u`
This is due to wrong usage of 'uniq -u'. The meaning of '-u' in 'uniq' is subtly different than '-u' in 'sort': In 'sort', it means "print each line once" i.e. removing duplicates. In 'uniq', it means "print only unique lines" i.e. lines which appear only once. The equivalent of 'sort -u' is 'sort|uniq'. Since all lines in your input had duplicates, 'uniq -u' printed none. The following will demonstrate: $ printf "a\nb\na\nc\nb\n" a b a c b $ printf "a\nb\na\nc\nb\n" | sort -u a b c $ printf "a\nb\na\nc\nb\n" | sort | uniq a b c $ printf "a\nb\na\nc\nb\n" | sort | uniq -u c As such I'm closing this bug, but discussion can continue by replying to this thread. regards, - assaf