diff options
| author | Craig Leres <leres@FreeBSD.org> | 2020-08-23 17:46:10 +0000 |
|---|---|---|
| committer | Craig Leres <leres@FreeBSD.org> | 2020-08-23 17:46:10 +0000 |
| commit | b9f65df40a2b7c510c33a9adb443650ac7d506e0 (patch) | |
| tree | 2941388b39f672af2ccdad9a707036908abc7ab7 /usr.bin | |
| parent | 45e4833bdbcd27cc81f31791ce41011fab785c61 (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/grep/zgrep.1 | 24 | ||||
| -rwxr-xr-x | usr.bin/grep/zgrep.sh | 50 |
2 files changed, 61 insertions, 13 deletions
diff --git a/usr.bin/grep/zgrep.1 b/usr.bin/grep/zgrep.1 index 332f980feca7..e300bf54b6d8 100644 --- a/usr.bin/grep/zgrep.1 +++ b/usr.bin/grep/zgrep.1 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 21, 2018 +.Dd July 20, 2020 .Dt ZGREP 1 .Os .Sh NAME @@ -86,9 +86,29 @@ to read compressed files. .Sh SEE ALSO .Xr bzip2 1 , .Xr grep 1 , -.Xr xz 1 +.Xr gzip 1 , +.Xr xz 1 , +.Xr zstd 1 .Sh AUTHORS This version of the .Nm utility was written by .An Thomas Klausner Aq Mt wiz@NetBSD.org . +.Sh BUGS +.Xr zgrep 1 +does not handle flags that take arguments if there is no whitespace +between the flag and the argument, for example: +.Pp +.Dl "zgrep -enfs /etc/rpc" +.Pp +When more than one +.Fl e +flag is used matching +should occur for any of the patterns (similar to multiple patterns +supplied in a file with the +.Fl f +flag). +.Xr zgrep 1 +only matches the last +.Fl e +pattern. diff --git a/usr.bin/grep/zgrep.sh b/usr.bin/grep/zgrep.sh index c645b1ca5907..acbcb48770a7 100755 --- a/usr.bin/grep/zgrep.sh +++ b/usr.bin/grep/zgrep.sh @@ -29,6 +29,7 @@ grep=grep zcat=zstdcat endofopts=0 +pattern_file=0 pattern_found=0 grep_args="" hyphen=0 @@ -75,18 +76,39 @@ while [ $# -gt 0 -a ${endofopts} -eq 0 ] do case $1 in # from GNU grep-2.5.1 -- keep in sync! - -[ABCDXdefm]) + --) + shift + endofopts=1 + ;; + --file=*) + pattern_file=1 + grep_args="${grep_args} ${1}" + shift + ;; + --regexp=*) + pattern="${1#--regexp=}" + pattern_found=1 + shift + ;; + --*) + grep_args="${grep_args} $1" + shift + ;; + -*[ABCDXdefm]) if [ $# -lt 2 ] then echo "${prg}: missing argument for $1 flag" >&2 exit 1 fi case $1 in - -e) + -*e) pattern="$2" pattern_found=1 shift 2 - break + continue + ;; + -*f) + pattern_file=1 ;; *) ;; @@ -94,10 +116,6 @@ do grep_args="${grep_args} $1 $2" shift 2 ;; - --) - shift - endofopts=1 - ;; -) hyphen=1 shift @@ -125,7 +143,7 @@ do done # if no -e option was found, take next argument as grep-pattern -if [ ${pattern_found} -lt 1 ] +if [ ${pattern_file} -eq 0 -a ${pattern_found} -eq 0 ] then if [ $# -ge 1 ]; then pattern="$1" @@ -136,6 +154,7 @@ then echo "${prg}: missing pattern" >&2 exit 1 fi + pattern_found=1 fi ret=0 @@ -143,15 +162,24 @@ ret=0 if [ $# -lt 1 ] then # ... on stdin - ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" - || ret=$? + if [ ${pattern_file} -eq 0 ]; then + ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" - || ret=$? + else + ${cattool} ${catargs} - | ${grep} ${grep_args} -- - || ret=$? + fi else # ... on all files given on the command line if [ ${silent} -lt 1 -a $# -gt 1 ]; then grep_args="-H ${grep_args}" fi for file; do - ${cattool} ${catargs} -- "${file}" | - ${grep} --label="${file}" ${grep_args} -- "${pattern}" - || ret=$? + if [ ${pattern_file} -eq 0 ]; then + ${cattool} ${catargs} -- "${file}" | + ${grep} --label="${file}" ${grep_args} -- "${pattern}" - || ret=$? + else + ${cattool} ${catargs} -- "${file}" | + ${grep} --label="${file}" ${grep_args} -- - || ret=$? + fi done fi |
