[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Grep-devel] [PATCH] Non-zero counts with --only-matching and --count
From: |
roel . kluin |
Subject: |
[Grep-devel] [PATCH] Non-zero counts with --only-matching and --count |
Date: |
Sat, 6 Oct 2018 14:33:09 +0200 |
From: "Roelof J.C. Kluin" <address@hidden>
* src/grep.c (only-matching, count): only-matching non zero counts
* doc/grep.in.1 (only-matching, count): non-zero counts in manual
* doc/grep.texi (only-matching, count): non-zero counts documented
Signed-off-by: Roelof J.C. Kluin <address@hidden>
---
doc/grep.in.1 | 3 ++-
doc/grep.texi | 2 ++
src/grep.c | 3 ++-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/doc/grep.in.1 b/doc/grep.in.1
index 9d0d494..d01a801 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -352,7 +352,8 @@ non-matching lines.
.TP
.BR \-o ", " \-\^\-only\-matching
Print only the matched (non-empty) parts of a matching line,
-with each such part on a separate output line.
+with each such part on a separate output line. When used in
+conjunction with -c or --count, list only non-zero counts.
.TP
.BR \-q ", " \-\^\-quiet ", " \-\^\-silent
Quiet; do not write anything to standard output.
diff --git a/doc/grep.texi b/doc/grep.texi
index 1b37c98..ab4cd96 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -365,6 +365,8 @@ with each such part on a separate output line.
Output lines use the same delimiters as input, and delimiters are null
bytes if @option{-z} (@option{--null-data}) is also used (@pxref{Other
Options}).
+When used in conjunction with @option{-o} (@option{--count}), instead only
+non-zero counts are listed.
@item -q
@itemx --quiet
diff --git a/src/grep.c b/src/grep.c
index fec9a53..9a3c990 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1849,7 +1849,7 @@ grepdesc (int desc, bool command_line)
}
count = grep (desc, &st, &ineof);
- if (count_matches)
+ if (count_matches && (count || !only_matching))
{
if (out_file)
{
@@ -1952,6 +1952,7 @@ Output control:\n\
"));
printf (_("\
-o, --only-matching show only nonempty parts of lines that match\n\
+ or non-zero counts\n\
-q, --quiet, --silent suppress all normal output\n\
--binary-files=TYPE assume that binary files are TYPE;\n\
TYPE is 'binary', 'text', or 'without-match'\n\
--
2.19.0
- [Grep-devel] [PATCH] Non-zero counts with --only-matching and --count,
roel . kluin <=