]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: Add -l flag as in grep(1)
authorAlejandro Colomar <alx.manpages@gmail.com>
Sat, 14 May 2022 16:22:47 +0000 (18:22 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:29:01 +0000 (21:29 +0100)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc
share/man/man1/grepc.1

index 42a736ab16deca2e62b3904be48809d2c57dc336..80def61434490189279055fdae4a87c0a3cef22d 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -5,6 +5,7 @@
 git='no';
 ext='\.[ch]$';
 FILES='.';
+lflag='';
 kflag='no';
 tflag='no';
 t_enum='no';
@@ -22,7 +23,7 @@ grepc_usage()
 
 grepc_parse_cmd()
 {
-       while getopts "ghkt:x:" opt; do
+       while getopts "lghkt:x:" opt; do
                case "$opt" in
                g)
                        git='yes';
@@ -34,6 +35,10 @@ grepc_parse_cmd()
                k)
                        kflag='yes';
                        ;;
+               l)
+                       lflag='-l';
+                       kflag='yes';
+                       ;;
                t)
                        case "$OPTARG" in
                        e)
@@ -102,7 +107,7 @@ grepc_helper()
        xargs grep -lPI "$1" <"$files" \
        | xargs grep -lP  "$2" \
        | sort \
-       | xargs pcregrep -Mn "$3" /dev/null \
+       | xargs pcregrep $lflag -Mn "$3" /dev/null \
        | if [ "$kflag" = 'no' ]; then
                sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n/';
        else
@@ -350,7 +355,12 @@ main()
        grepc_parse_cmd $@;
        grepc_find_files "$identifier";
        grepc_search "$identifier" \
-       | sed -n '/./,$p';
+       | if [ -n "$lflag" ]; then
+               sort \
+               | uniq;
+       else
+               sed -n '/./,$p';
+       fi;
 }
 
 
index 5bdbb88c1c144b3570b7df60f12627dfaf16ac12..d860ce473e074fbdce47c35651d400b63fa11da4 100644 (file)
@@ -70,6 +70,12 @@ Compact (kurz) output.
 Don't print extra newlines
 (the header is printed in the same line as the first line of a match).
 .TP
+.B \-l
+Suppress normal output;
+instead print the name of each input file
+from which output would normally have been printed.
+Each file is only printed once.
+.TP
 .BI \-t " type"
 Restrict the search to a specific
 .I type