bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23268: sort ant uniq bug report


From: Assaf Gordon
Subject: bug#23268: sort ant uniq bug report
Date: Mon, 11 Apr 2016 11:52:18 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]