GNU bug report logs -
#23268
sort ant uniq bug report
Previous Next
Reported by: 126 <cool_navy <at> 126.com>
Date: Mon, 11 Apr 2016 15:32:01 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 23268 <at> debbugs.gnu.org (full text, mbox):
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
This bug report was last modified 6 years and 261 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.