diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-14 18:22:47 +0200 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-14 18:22:47 +0200 |
commit | 40b53809269763323817bd1f87bb67d695df9fd2 (patch) | |
tree | bf47d062062b603889487146981694978695c687 | |
parent | f9714f8a986fceeaa03eb3fcffa0cfebf2013422 (diff) |
grepc, grepc.1: Add -l flag as in grep(1)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rwxr-xr-x | bin/grepc | 16 | ||||
-rw-r--r-- | share/man/man1/grepc.1 | 6 |
2 files changed, 19 insertions, 3 deletions
@@ -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; } diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1 index 5bdbb88..d860ce4 100644 --- a/share/man/man1/grepc.1 +++ b/share/man/man1/grepc.1 @@ -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 |