bug-grep
[Top][All Lists]
Advanced

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

bug#20990: RFC: [PATCH] accept new option: --files0-from=F


From: Jim Meyering
Subject: bug#20990: RFC: [PATCH] accept new option: --files0-from=F
Date: Sun, 5 Jul 2015 20:32:23 -0700

Here is a patch to teach grep the --files0-from=F option.
That is the same option that is already supported by wc, du and sort
in the GNU coreutils.

This option allows one to specify NUL-separated file names in the file
argument, F.  When I would receive requests to add this option to other
programs from the coreutils, I would refuse, because one can obtain
similar behavior by using xargs like this:

  xargs -0 PROGRAM < F

The "use xargs" argument does not work for programs like wc, du and sort.
In those cases, concatenating the output from multiple invocations
(as that xargs usage would do) does not result in the same output as
using --files0-from=F, e.g., because of totals or, for sort, because
the result cannot be the concatenation of separately-sorted outputs.

For most uses of grep, it would be ok to process separate lists of
file names in batches and to concatenate the results, but not with
the --count (-c) option.  The count must reflect the total over
all files processed.

Also, more subtly, consider what would happen when the last batch of file
name inputs to xargs happens to contain only one name. The output from
that final invocation of grep (assuming no option like -h or -H) would
omit the "FILENAME:" prefix for any lines matched from that final file.

This patch depends on the perl-based test infrastructure I have just
posted, because the tests are very similar to those for the three tools
from the coreutils.

Attachment: 0001-accept-new-option-files0-from-F.patch
Description: Text Data


reply via email to

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