coreutils
[Top][All Lists]
Advanced

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

[PATCH]: wc: add --total={auto,never,always,only} option


From: Pádraig Brady
Subject: [PATCH]: wc: add --total={auto,never,always,only} option
Date: Sun, 25 Sep 2022 18:40:26 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Thunderbird/98.0

On 12/09/2022 17:33, Pádraig Brady wrote:
On 12/09/2022 16:28, Mike Jonkmans wrote:
On Mon, Sep 12, 2022 at 03:45:53PM +0200, Jim Meyering wrote:
On Mon, Sep 12, 2022, 14:53 Pádraig Brady <P@draigbrady.com> wrote:

On 12/09/2022 10:20, David Pinto wrote:
On Sun, 26 Jun 2022 at 00:49, David Pinto <carandraug+dev@gmail.com>
wrote:
Hi

A couple of years ago [1] someone made a feature request for a wc
option that would skip the total line when processing multiple files.
I didn't see anyone commenting against it and it is something that I'm
constantly hacking with `head -n-1`.

I've attached a patch that implements a new `--no-total` option to wc.
I believe this patch to be trivial enough that I can't claim copyright
for anything.

Best regards
David

[1] https://lists.gnu.org/archive/html/coreutils/2015-11/msg00064.html

Hi

It's been almost 3 months without any reply.  I hope it's OK to bump
it again.  I've just changed the subject line to make it clear there
is a patch attached.

Thanks for the bump.

This is one of those marginal ones since
there is no extra functionality provided
by bringing the logic within the utility.

The following function would achieve the desired functionality:

     wc-no-total() { wc "$@" /dev/null | head -n-2; }

Since it's easy enough to achieve with a single extra processing step,
Given the above, I'd be 60:40 against adding a --no-total option.
But thinking more, the above is awkward to combine with the --files0-from
option.
So you'd need a separate invocation in that case like:

     { find files -print0; printf '%s\0' /dev/null; } |
     wc --files0-from=- |
     head -n2

Even though there is still no extra functionality,
the above is starting to get a bit obtuse.

If we lifted the restriction with --files0-from
to also allow file names to be specified on the command line
(and for those to be processed after stdin),
it would mean the wc-no-total() function above would be general,
and would work for all wc invocations.

Though a --no-total option is looking more appealing
given the above considerations. I.e. that the
wc-no-total() implementation isn't obvious,
and we'd have to change wc anyway to make it general.

So I'd be 55:45 for adding this option.


Good arguments. +1

I think it is nice to have.

What about only printing the total?
With 'wc --total' or 'wc -t'.

Well ` | tail -n1` will always work to get
the total count irrespective on the number
of files processed.

I suppose we could support --total={auto,never,always,only} as the interface.
I'll think about it.

The attached implements this, and operates like:

$ wc --total=only src/wc.c /dev/null
1037 3635 30277

$ wc --total=always src/wc.c
 1037  3635 30277 src/wc.c
 1037  3635 30277 total

$ wc --total=never src/wc.c /dev/null
   1037    3635   30277 src/wc.c
      0       0       0 /dev/null

$ wc --total=auto src/wc.c /dev/null
   1037    3635   30277 src/wc.c
      0       0       0 /dev/null
   1037    3635   30277 total

cheers,
Pádraig

Attachment: wc--total.patch
Description: Text Data


reply via email to

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