summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/gzip
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-05-12 16:20:26 +0000
committerwosch <wosch@FreeBSD.org>1996-05-12 16:20:26 +0000
commitaf3757a685be64f1653129d280d89b4ec7fa7110 (patch)
tree7b1020b63b379ef7cdf866849cfceff8491d5cfd /gnu/usr.bin/gzip
parente4ed666230d40e4a82e24f26346b323be0442e1a (diff)
downloadFreeBSD-src-af3757a685be64f1653129d280d89b4ec7fa7110.zip
FreeBSD-src-af3757a685be64f1653129d280d89b4ec7fa7110.tar.gz
faster
average 2-3 x for option -h or -q 10 x handle option -q and -L better exit status, similar to grep (0: matches found 1: no matches found 2: error)
Diffstat (limited to 'gnu/usr.bin/gzip')
-rw-r--r--gnu/usr.bin/gzip/zgrep.getopt72
1 files changed, 72 insertions, 0 deletions
diff --git a/gnu/usr.bin/gzip/zgrep.getopt b/gnu/usr.bin/gzip/zgrep.getopt
new file mode 100644
index 0000000..54d56d0
--- /dev/null
+++ b/gnu/usr.bin/gzip/zgrep.getopt
@@ -0,0 +1,72 @@
+#!/bin/sh
+# (c) Wolfram Schneider, Berlin. April 1996.
+#
+# zgrep - search possibly compressed files for a regular expression
+#
+# $Id: zgrep,v 1.4 1996/04/28 18:43:47 wosch Exp $
+
+
+PATH=/bin:/usr/bin:$PATH; export PATH
+
+# grep variant
+case "$0" in
+ *egrep) grep=${EGREP-egrep} ;;
+ *fgrep) grep=${FGREP-fgrep} ;;
+ *) grep=${GREP-grep} ;;
+esac
+
+gzip=gzip gzipopt="-cdfq" pattern= grepopt= files= line= header=
+set -- `getopt "0123456789A:B:CEFGVX:bce:f:hiLlnqsvwxy" "$@"`
+
+# check options
+while :
+do
+ case "$1" in
+ --) shift; break;; # EOF options
+ -e|-f) pattern="$1 $2"; shift;; # -f file
+ -l|-L) line=$1; grepopt="$grepopt $1";;
+ -h|-q) header=$1; grepopt="$grepopt $1";;
+ *) grepopt="$grepopt $1";; # rest
+ esac
+ shift
+done
+
+# check pattern
+case X"$pattern" in
+ X) case $# in
+ 0) echo "usage: $0 [grep_options] pattern [files]"; exit 1;;
+ *) pattern=$1; shift;;
+ esac
+esac
+
+
+files="$@"
+# no shell loop neccessary for option -q or -h
+# and a single file or reading from stdin
+case "$header"X"$#" in
+ -h*|-q*|X0|X1) $gzip $gzipopt $files | $grep $grepopt $pattern
+ exit $?;;
+esac
+
+
+exit=1
+for f in $files
+do
+ case "$line" in
+ -l|-L) if $gzip $gzipopt $f |
+ $grep $grepopt $pattern >/dev/null
+ then
+ echo $f
+ fi
+ ;;
+ *) $gzip $gzipopt $f | $grep $grepopt $pattern |
+ sed "s%^%${f}:%";;
+ esac
+
+ case $? in
+ 2) exit=$?;;
+ 0) case "$exit" in 2);; 1) exit=0;; esac;;
+ esac
+done
+
+exit $exit
OpenPOWER on IntegriCloud