/[packages]/cauldron/bzip2/current/SOURCES/bzgrep
ViewVC logotype

Contents of /cauldron/bzip2/current/SOURCES/bzgrep

Parent Directory Parent Directory | Revision Log Revision Log


Revision 241 - (show annotations) (download)
Fri Jan 7 12:50:50 2011 UTC (13 years, 3 months ago) by pterjan
File size: 1438 byte(s)
imported package bzip2
1 #!/bin/sh
2
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>
5 # Adapted to bzip2 by Bernhard Rosenkraenzer <bero@redhat.com>
6
7 PATH="/usr/bin:$PATH"; export PATH
8
9 prog=`echo $0 | sed 's|.*/||'`
10 case "$prog" in
11 *egrep) grep=${EGREP-egrep} ;;
12 *fgrep) grep=${FGREP-fgrep} ;;
13 *) grep=${GREP-grep} ;;
14 esac
15 pat=""
16 while test $# -ne 0; do
17 case "$1" in
18 -e | -f) opt="$opt $1"; shift; pat="$1"
19 if test "$grep" = grep; then # grep is buggy with -e on SVR4
20 grep=egrep
21 fi;;
22 -A | -B) opt="$opt $1 $2"; shift;;
23 -*) opt="$opt $1";;
24 *) if test -z "$pat"; then
25 pat="$1"
26 else
27 break;
28 fi;;
29 esac
30 shift
31 done
32
33 if test -z "$pat"; then
34 echo "grep through bzip2 files"
35 echo "usage: $prog [grep_options] pattern [files]"
36 exit 1
37 fi
38
39 list=0
40 silent=0
41 op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
42 case "$op" in
43 *l*) list=1
44 esac
45 case "$op" in
46 *h*) silent=1
47 esac
48
49 if test $# -eq 0; then
50 bzip2 -cdfq | $grep $opt "$pat"
51 exit $?
52 fi
53
54 res=0
55 for i do
56 if test $list -eq 1; then
57 bzip2 -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
58 r=$?
59 elif test $# -eq 1 -o $silent -eq 1; then
60 bzip2 -cdfq "$i" | $grep $opt "$pat"
61 r=$?
62 else
63 bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
64 r=$?
65 fi
66 test "$r" -ne 0 && res="$r"
67 done
68 exit $res

  ViewVC Help
Powered by ViewVC 1.1.30