4 # zgrep -- a wrapper around a grep program that decompresses files as needed
5 # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
7 PATH="BINDIR:$PATH"; export PATH
9 prog=`echo $0 | sed 's|.*/||'`
11 *egrep) grep=${EGREP-egrep} ;;
12 *fgrep) grep=${FGREP-fgrep} ;;
13 *) grep=${GREP-grep} ;;
16 while test $# -ne 0; do
18 -e | -f) opt="$opt $1"; shift; pat="$1"
19 if test "$grep" = grep; then # grep is buggy with -e on SVR4
23 *) if test -z "$pat"; then
32 if test -z "$pat"; then
33 echo "grep through gzip files"
34 echo "usage: $prog [grep_options] pattern [files]"
40 op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
48 if test $# -eq 0; then
49 gzip -cdfq | $grep $opt "$pat"
55 if test $list -eq 1; then
56 gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
58 elif test $# -eq 1 -o $silent -eq 1; then
59 gzip -cdfq "$i" | $grep $opt "$pat"
62 gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
65 test "$r" -ne 0 && res="$r"