summaryrefslogtreecommitdiffstats
path: root/bin/grepc
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-14 18:22:47 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-14 18:22:47 +0200
commit40b53809269763323817bd1f87bb67d695df9fd2 (patch)
treebf47d062062b603889487146981694978695c687 /bin/grepc
parentf9714f8a986fceeaa03eb3fcffa0cfebf2013422 (diff)
grepc, grepc.1: Add -l flag as in grep(1)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'bin/grepc')
-rwxr-xr-xbin/grepc16
1 files changed, 13 insertions, 3 deletions
diff --git a/bin/grepc b/bin/grepc
index 42a736a..80def61 100755
--- 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;
}