]> git.ipfire.org Git - thirdparty/coreutils.git/commit
wc: add --total={auto,never,always,only} option
authorPádraig Brady <P@draigBrady.com>
Sat, 25 Jun 2022 23:27:06 +0000 (00:27 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 26 Sep 2022 14:04:56 +0000 (15:04 +0100)
commitce2b875cd725d8d64aae5b1f250382f3fa987593
tree981b8a836395a7879424c83348037418346cbbf8
parent627c9a97c1054afdbe6870f3b64d42e7fccaf9eb
wc: add --total={auto,never,always,only} option

without this option, control of when the total is output
is quite awkward. Consider trying to suppress the total line,
which could be achieved with something like:

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

As well as being non obvious, it's also non general.
It would give a non failure, but zero count if passed a file on stdin.
Also it doesn't work in conjunction with the --files0-from option,
which would need to be handled differently with something like:

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

Also getting just the total can be awkward as file names
are only suppressed when processing stdin, and
also a total line is only printed if processing more than one file.
For completness this might be achieved currently with:

  wc-only-total() {
    wc "$@" |
    tail -n1 |
    sed 's/^ *//; s/ [^ 0-9]*$//'
  }

* src/wc.c: Add new --total option.
* tests/misc/wc-total.sh: New test suite for the new option.
* tests/local.mk: Reference the new test.
* doc/coreutils.texi (wc invocation): Document the new option.
* THANKS.in: Add suggestor.
* NEWS: Mention the new feature.
NEWS
THANKS.in
doc/coreutils.texi
src/wc.c
tests/local.mk
tests/misc/wc-total.sh [new file with mode: 0755]