From bebb11c38f6ef3644c7b4a1af61c3b890249c59c Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 5 Nov 2023 13:31:33 +0100 Subject: bin/grepc, grepc.1: -c: Add option to count matches As in pcre2grep(1) and grep(1). Signed-off-by: Alejandro Colomar --- bin/grepc | 13 +++++++++++-- share/man/man1/grepc.1 | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bin/grepc b/bin/grepc index c8e49ca..1174bc0 100755 --- 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; } diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1 index 7845255..e1236c7 100644 --- a/share/man/man1/grepc.1 +++ b/share/man/man1/grepc.1 @@ -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 -- cgit v1.2.3