From 6fc13c5479d9c71ab3a4be86a6e1593868ca8b3e Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 5 Nov 2023 03:12:53 +0100 Subject: bin/grepc, grepc.1: -n: Add option to control printing of line numbers Signed-off-by: Alejandro Colomar --- bin/grepc | 8 ++++++-- share/man/man1/grepc.1 | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/grepc b/bin/grepc index f37510d..23de67d 100755 --- a/bin/grepc +++ b/bin/grepc @@ -10,6 +10,7 @@ h='-H'; i=''; k='no'; l=''; +n=''; t='no'; t_e='no'; t_fp='no'; @@ -43,7 +44,7 @@ grepc_err() grepc_parse_cmd() { - while getopts "A:B:C:chiklt:" opt; do + while getopts "A:B:C:chiklnt:" opt; do case "$opt" in A) A="-A$OPTARG"; @@ -70,6 +71,9 @@ grepc_parse_cmd() l='-l'; k='yes'; ;; + n) + n='-n'; + ;; t) case "$OPTARG" in e) @@ -254,7 +258,7 @@ grepc_search() opts="$opts $i"; opts="$opts $l"; opts="$opts -M"; - opts="$opts -n"; + opts="$opts $n"; if test -z "$files"; then pcre2grep $opts -f "$patterns"; diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1 index ac124f3..f1ff4eb 100644 --- a/share/man/man1/grepc.1 +++ b/share/man/man1/grepc.1 @@ -162,6 +162,10 @@ instead print the name of each input file from which output would normally have been printed. Each file is only printed once. .TP +.B \-n +Prefix each line of output with the +1-based line number within its input file. +.TP .BI \-t " type" Restrict the search to a specific .I type @@ -185,7 +189,7 @@ If you need to read a non-seekable file, redirect it to the standard input. .SH EXAMPLES .EX -.RB \(ti/src/nginx/unit$ " grepc nxt_sprintf .;" +.RB \(ti/src/nginx/unit$ " grepc \-n nxt_sprintf .;" \& \& \&./src/nxt_sprintf.h:15: -- cgit v1.2.3