[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: improved support for grouping in uniq
From: |
Eric Blake |
Subject: |
Re: RFC: improved support for grouping in uniq |
Date: |
Wed, 02 Mar 2011 09:57:13 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 |
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 address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature