coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH]: uniq: add "--group" option


From: Pádraig Brady
Subject: Re: [PATCH]: uniq: add "--group" option
Date: Thu, 21 Feb 2013 01:47:00 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 02/20/2013 06:44 PM, Assaf Gordon wrote:
Hello,

Attached is a suggestion for "--group" option in uniq, as discussed here:
   http://lists.gnu.org/archive/html/coreutils/2011-03/msg00000.html
   http://lists.gnu.org/archive/html/coreutils/2012-03/msg00052.html

The patch adds two parameters:
       --group=[method]  separate each unique line (whether duplicated or not)
                         with a marker.
                         method={none,separate(default),prepend,append,both)
       --group-separator=SEP   with --group, separates group using SEP
                         (default: empty line)


Yes I think this is useful.
Since I suggested it though I'm biased :)
Currently I'm 60:40 for adding it.
Just after I originally did the --all-repeated={none(default),prepend,separate} 
patch,
I had wished I'd gone for the more general --group solution.

So whether to have --group as a separate option,
or to use it in conjunction with -u and -D etc.?
That's a tough call, but I'd be just on the side of
using --group in combination with others, and thus
having --all-repeated having redundant parameters
(which may be deprecated in future).

--group-sep is probably overkill.
I'd just use \n or \0 if -z specified.

As for separation methods I'd just go with what we have for
--all-repeated (but remove 'none' which wouldn't be useful with --group),
as we've never had requests for anything else. so:
--group={prepend, separate(default)}

So on to operation...

> And it behaves "as expected":
> ===
> $ printf "a\na\na\nb\nc\nc\n" | ./src/uniq --group-sep="--" --group=separate
> a
> --
> b
> --
> c

The above isn't that useful and could be done with sed.
The most useful mode of --group probably would be to
so _all_ lines appropriately grouped. I.E. --group
without other uniq selection options would behave
as if -u and -D were specified in combination and do:

$ printf '%s\n' a a b c c | src/uniq --group | sed 's/^$/:/'
a
a
:
b
:
c
c

$ printf '%s\n' a b b c | src/uniq -D --group | sed 's/^$/:/'
b
b
:
c
c

Supporting -u or -d with --group wouldn't be useful either really.
It's probably most consistent to just disallow those combinations.

> ===
>
> The added tests check all sorts of combinations.
>
> If this is the right direction, I'll send an updated patch (with 
NEWS/docs/etc.).

thanks!
Pádraig.



reply via email to

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