# RE: [PATCH] Completion must sort before using uniq

3 messages from 2012-11-23 to 2012-11-23. Participants: Joachim Schmitz, Sascha Cunz.
Thread: https://gitlist.dev/t/32177

## Joachim Schmitz, 2012-11-23 12:15

Subject: RE: [PATCH] Completion must sort before using uniq
Message-ID: <003b01cdc974$4cdd1900$e6974b00$@schmitz-digital.de>
URL: https://gitlist.dev/e/003b01cdc974%244cdd1900%24e6974b00%24%40schmitz-digital.de
In-Reply-To: <CAFj1UpEMKq9zH3nbLwYrNZRmd52_KEcN5BBrzGg2jxCzd+fsbA@mail.gmail.com>

```
Re-adding git@vger...

> From: Marc Khouzam [mailto:marc.khouzam@gmail.com]
> Sent: Friday, November 23, 2012 11:51 AM
> To: Joachim Schmitz
> Cc: szeder@ira.uka.de; felipe.contreras@gmail.com
> Subject: Re: [PATCH] Completion must sort before using uniq
> 
> On Fri, Nov 23, 2012 at 3:10 AM, Joachim Schmitz
> <jojo@schmitz-digital.de> wrote:
> > Marc Khouzam wrote:
> >> The uniq program only works with sorted input.  The man page states
> >> "uniq prints the unique lines in a sorted file".
> > ...
> >> --- a/contrib/completion/git-completion.bash
> >> +++ b/contrib/completion/git-completion.bash
> >> @@ -321,7 +321,7 @@ __git_refs ()
> >>                                if [[ "$ref" == "$cur"* ]]; then
> >>                                        echo "$ref"
> >>                                fi
> >> -                       done | uniq -u
> >> +                       done | sort | uniq -u
> >
> > Is 'sort -u' not universally available and sufficient here? It is POSIX
> > at least:
> > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html
> 
> "-u Unique: suppress all but one in each set of lines having equal
> keys. If used with the -c option, check that there are no lines with
> duplicate keys, in addition to checking that the input file is
> sorted."
> 
> What the code aims to do is to only show lines that are not
> duplicated.  'sort -u' would still output one line for each duplicated
> one.  It seems 'sort -u' is the equivalent of 'sort | uniq' but won't
> replace 'sort | uniq -u'.

I can't see the difference and in fact don't understand uniq's -u option al all
Linux man pages say: "only print unique lines", but that is what uniq does by default anyway?!?

> Is 'sort | uniq -u' not POSIX?

It is. It is one process more though.

Bye, Jojo

```

## Sascha Cunz, 2012-11-23 12:26

Subject: Re: [PATCH] Completion must sort before using uniq
Message-ID: <2630847.8aaR79v5Od@blacky>
URL: https://gitlist.dev/e/2630847.8aaR79v5Od%40blacky
In-Reply-To: <003b01cdc974$4cdd1900$e6974b00$@schmitz-digital.de>

```
> I can't see the difference and in fact don't understand uniq's -u option al
> all Linux man pages say: "only print unique lines", but that is what uniq
> does by default anyway?!?

>From the german translation of uniq's man-page, you can deduct that "only 
print unique lines" actually means: "print lines that are _not repeated_ in 
the input".

A short test confirms that. i.e.:

	printf "a\nb\nb\nc\n" | uniq -u

gives:
	a
	c

Sascha

```

## Joachim Schmitz, 2012-11-23 12:36

Subject: RE: [PATCH] Completion must sort before using uniq
Message-ID: <003c01cdc977$1a8a60e0$4f9f22a0$@schmitz-digital.de>
URL: https://gitlist.dev/e/003c01cdc977%241a8a60e0%244f9f22a0%24%40schmitz-digital.de
In-Reply-To: <2630847.8aaR79v5Od@blacky>

```
> From: Sascha Cunz [mailto:sascha-ml@babbelbox.org]
> Sent: Friday, November 23, 2012 1:26 PM
> To: Joachim Schmitz
> Cc: 'Marc Khouzam'; git@vger.kernel.org; szeder@ira.uka.de; felipe.contreras@gmail.com
> Subject: Re: [PATCH] Completion must sort before using uniq
> 
> > I can't see the difference and in fact don't understand uniq's -u option al
> > all Linux man pages say: "only print unique lines", but that is what uniq
> > does by default anyway?!?
> 
> From the german translation of uniq's man-page, you can deduct that "only
> print unique lines" actually means: "print lines that are _not repeated_ in
> the input".
> 
> A short test confirms that. i.e.:
> 
> 	printf "a\nb\nb\nc\n" | uniq -u
> 
> gives:
> 	a
> 	c

Ah, OK, then I rest my case. Sorry for the noise.

```
