summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-11-05 13:31:33 +0100
committerAlejandro Colomar <alx@kernel.org>2023-11-05 17:13:49 +0100
commitbebb11c38f6ef3644c7b4a1af61c3b890249c59c (patch)
treef1da9e98d32d337c5a0ffe3b06ed0e4ff13ef688
parentab07b22a4dd31ccb9beef150fd478c1f8ce6bf31 (diff)
bin/grepc, grepc.1: -c: Add option to count matches
As in pcre2grep(1) and grep(1). Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rwxr-xr-xbin/grepc13
-rw-r--r--share/man/man1/grepc.14
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