3
# Bzgrep wrapped for bzip2,
4
# adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
6
## zgrep -- a wrapper around a grep program that decompresses files as needed
7
## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
9
PATH="/usr/bin:$PATH"; export PATH
11
prog=`echo $0 | sed 's|.*/||'`
13
*egrep) grep=${EGREP-egrep} ;;
14
*fgrep) grep=${FGREP-fgrep} ;;
15
*) 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
24
-A | -B) opt="$opt $1 $2"; shift;;
26
*) if test -z "$pat"; then
35
if test -z "$pat"; then
36
echo "grep through bzip2 files"
37
echo "usage: $prog [grep_options] pattern [files]"
43
op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
51
if test $# -eq 0; then
52
bzip2 -cdfq | $grep $opt "$pat"
58
if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
59
if test $list -eq 1; then
60
bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
62
elif test $# -eq 1 -o $silent -eq 1; then
63
bzip2 -cdfq "$i" | $grep $opt "$pat"
69
j=`printf "%s" "$j" | tr '\n' ' '`
70
bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
73
test "$r" -ne 0 && res="$r"