]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
bin/grepc, grepc.1: -c: Add option to count matches
authorAlejandro Colomar <alx@kernel.org>
Sun, 5 Nov 2023 12:31:33 +0000 (13:31 +0100)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:29:23 +0000 (21:29 +0100)
As in pcre2grep(1) and grep(1).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
bin/grepc
share/man/man1/grepc.1

index c8e49caf595653bf17917f19ea9365f364cea5b6..1174bc064d84bd87813f187110ed549d111f8f57 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -5,6 +5,7 @@
 A='';
 B='';
 C='';
+c='';
 h='-H';
 i='';
 k='no';
@@ -44,7 +45,7 @@ grepc_err()
 
 grepc_parse_cmd()
 {
-       while getopts "A:B:C:hiklnrt:" opt; do
+       while getopts "A:B:C:chiklnrt:" opt; do
                case "$opt" in
                A)
                        A="-A$OPTARG";
@@ -55,6 +56,9 @@ grepc_parse_cmd()
                C)
                        C="-C$OPTARG";
                        ;;
+               c)
+                       c='-c';
+                       ;;
                h)
                        h='-h';
                        ;;
@@ -254,6 +258,7 @@ grepc_search()
        opts="$opts $A";
        opts="$opts $B";
        opts="$opts $C";
+       opts="$opts $c";
        opts="$opts $h";
        opts="$opts $i";
        opts="$opts $l";
@@ -264,7 +269,11 @@ grepc_search()
                pcre2grep $opts -f "$patterns";
        else
                find $files -type f \
-               | xargs grep -${i}lPI -- "$identifier" \
+               | if test -z "$c"; then
+                       xargs grep -${i}lPI -- "$identifier";
+               else
+                       cat;
+               fi \
                | xargs pcre2grep $opts -f "$patterns";
        fi;
 }
index 7845255216a0c05d43827786b00e7d85081badc8..e1236c7161ad66bd315d8dc63bfde3d6bfdaf060 100644 (file)
@@ -137,6 +137,10 @@ Print
 .I n
 lines of context surrounding a match.
 .TP
+.B \-c
+Do not print matches,
+and instead print a count of them.
+.TP
 .B \-h
 Suppress the prefixing of file names on output.
 .TP