3 # zgrep -- a wrapper around a grep program that decompresses files as needed
4 # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
6 # $FreeBSD: src/gnu/usr.bin/gzip/zgrep,v 1.3 1999/08/27 23:35:55 peter Exp $
7 # $DragonFly: src/gnu/usr.bin/gzip/Attic/zgrep,v 1.2 2003/06/17 04:25:46 dillon Exp $
9 prog=`echo $0 | sed 's|.*/||'`
11 *egrep) grep=${EGREP-egrep} ;;
12 *fgrep) grep=${FGREP-fgrep} ;;
13 *) grep=${GREP-grep} ;;
18 while test $# -ne 0; do
20 -e | -f) opt="$opt $1"; shift; pat="$1"
21 if test "$grep" = grep; then # grep is buggy with -e on SVR4
25 *) if test -z "$pat"; then
28 fileno=`expr $fileno + 1`
37 if test -z "$pat"; then
38 echo "grep through gzip files"
39 echo "usage: $prog [grep_options] pattern [files]"
45 op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
53 if test $fileno -eq 0; then
54 gzip -cdfq | $grep $opt "$pat"
57 eval set "$A" # files in $1, $2 ...
61 if test $list -eq 1; then
62 gzip -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
64 elif test $# -eq 1 -o $silent -eq 1; then
65 gzip -cdfq "$i" | $grep $opt "$pat"
68 gzip -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
71 test "$r" -ne 0 && res="$r"