[prev in list] [next in list] [prev in thread] [next in thread]
List: coreutils
Subject: Re: RFC: improved support for grouping in uniq
From: Eric Blake <eblake () redhat ! com>
Date: 2011-03-02 16:57:13
Message-ID: 4D6E76E9.30106 () redhat ! com
[Download RAW message or body]
On 03/02/2011 09:44 AM, Pádraig Brady wrote:
> -d, -D and -u make sense when used in isolation:
>
> $ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" | uniq -w1 -D
> 2 a
> 2 b
> 2 c
> $ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" | uniq -w1 -u
> 1 a
> 3 a
> pb-laptop:~$ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" | uniq -w1 -d
> 2 a
>
> However when you combine -u (suppress last output entry
> in a repeated group) with -d or -D it doesn't seem useful:
>
> $ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" | uniq -w1 -d -u
This behavior is required by POSIX (-d suppresses unique lines, -u
suppresses duplicate lines, so all lines are suppressed).
> $ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" | uniq -w1 -D -u
> 2 a
> 2 b
-D is a GNU invention, so we are free to make it more useful.
>
> Why I'm asking is to perhaps overload -u -D
> to support grouping like:
>
> $ printf "1 a\n2 a\n2 b\n2 c\n3 a\n" |
> uniq -w1 --unique=separated --all-repeated=separated
> 1 a
>
> 2 a
> 2 b
> 2 c
>
> 3 a
>
>
> Or maybe we should just add a new --group option to do the above?
A --group option sounds interesting, even in combination with the others:
$ printf "1 a\n2 a\n2 b\n3 a\n3 b\n4 a\n" | uniq -w1 -u --group
1 a
4 a
$ printf "1 a\n2 a\n2 b\n3 a\n3 b\n4 a\n" | uniq -w1 -D --group
2 a
2 b
3 a
3 b
$ printf "1 a\n2 a\n2 b\n3 a\n3 b\n4 a\n" | uniq -w1 --group
1 a
2 a
2 b
3 a
3 b
4 a
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic