diff options
Diffstat (limited to '')
-rw-r--r-- | bzgrep | 71 | ||||
-rw-r--r-- | bzgrep.1 | 56 |
2 files changed, 127 insertions, 0 deletions
@@ -0,0 +1,71 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Bzgrep wrapped for bzip2, | ||
4 | # adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux. | ||
5 | ## zgrep notice: | ||
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> | ||
8 | |||
9 | PATH="/usr/bin:$PATH"; export PATH | ||
10 | |||
11 | prog=`echo $0 | sed 's|.*/||'` | ||
12 | case "$prog" in | ||
13 | *egrep) grep=${EGREP-egrep} ;; | ||
14 | *fgrep) grep=${FGREP-fgrep} ;; | ||
15 | *) grep=${GREP-grep} ;; | ||
16 | esac | ||
17 | pat="" | ||
18 | while test $# -ne 0; do | ||
19 | case "$1" in | ||
20 | -e | -f) opt="$opt $1"; shift; pat="$1" | ||
21 | if test "$grep" = grep; then # grep is buggy with -e on SVR4 | ||
22 | grep=egrep | ||
23 | fi;; | ||
24 | -A | -B) opt="$opt $1 $2"; shift;; | ||
25 | -*) opt="$opt $1";; | ||
26 | *) if test -z "$pat"; then | ||
27 | pat="$1" | ||
28 | else | ||
29 | break; | ||
30 | fi;; | ||
31 | esac | ||
32 | shift | ||
33 | done | ||
34 | |||
35 | if test -z "$pat"; then | ||
36 | echo "grep through bzip2 files" | ||
37 | echo "usage: $prog [grep_options] pattern [files]" | ||
38 | exit 1 | ||
39 | fi | ||
40 | |||
41 | list=0 | ||
42 | silent=0 | ||
43 | op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'` | ||
44 | case "$op" in | ||
45 | *l*) list=1 | ||
46 | esac | ||
47 | case "$op" in | ||
48 | *h*) silent=1 | ||
49 | esac | ||
50 | |||
51 | if test $# -eq 0; then | ||
52 | bzip2 -cdfq | $grep $opt "$pat" | ||
53 | exit $? | ||
54 | fi | ||
55 | |||
56 | res=0 | ||
57 | for i do | ||
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 | ||
61 | r=$? | ||
62 | elif test $# -eq 1 -o $silent -eq 1; then | ||
63 | bzip2 -cdfq "$i" | $grep $opt "$pat" | ||
64 | r=$? | ||
65 | else | ||
66 | bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${i}:|" | ||
67 | r=$? | ||
68 | fi | ||
69 | test "$r" -ne 0 && res="$r" | ||
70 | done | ||
71 | exit $res | ||
diff --git a/bzgrep.1 b/bzgrep.1 new file mode 100644 index 0000000..930af8c --- /dev/null +++ b/bzgrep.1 | |||
@@ -0,0 +1,56 @@ | |||
1 | \"Shamelessly copied from zmore.1 by Philippe Troin <phil@fifi.org> | ||
2 | \"for Debian GNU/Linux | ||
3 | .TH BZGREP 1 | ||
4 | .SH NAME | ||
5 | bzgrep, bzfgrep, bzegrep \- search possibly bzip2 compressed files for a regular expression | ||
6 | .SH SYNOPSIS | ||
7 | .B bzgrep | ||
8 | [ grep_options ] | ||
9 | .BI [\ -e\ ] " pattern" | ||
10 | .IR filename ".\|.\|." | ||
11 | .br | ||
12 | .B bzegrep | ||
13 | [ egrep_options ] | ||
14 | .BI [\ -e\ ] " pattern" | ||
15 | .IR filename ".\|.\|." | ||
16 | .br | ||
17 | .B bzfgrep | ||
18 | [ fgrep_options ] | ||
19 | .BI [\ -e\ ] " pattern" | ||
20 | .IR filename ".\|.\|." | ||
21 | .SH DESCRIPTION | ||
22 | .IR Bzgrep | ||
23 | is used to invoke the | ||
24 | .I grep | ||
25 | on bzip2-compressed files. All options specified are passed directly to | ||
26 | .I grep. | ||
27 | If no file is specified, then the standard input is decompressed | ||
28 | if necessary and fed to grep. | ||
29 | Otherwise the given files are uncompressed if necessary and fed to | ||
30 | .I grep. | ||
31 | .PP | ||
32 | If | ||
33 | .I bzgrep | ||
34 | is invoked as | ||
35 | .I bzegrep | ||
36 | or | ||
37 | .I bzfgrep | ||
38 | then | ||
39 | .I egrep | ||
40 | or | ||
41 | .I fgrep | ||
42 | is used instead of | ||
43 | .I grep. | ||
44 | If the GREP environment variable is set, | ||
45 | .I bzgrep | ||
46 | uses it as the | ||
47 | .I grep | ||
48 | program to be invoked. For example: | ||
49 | |||
50 | for sh: GREP=fgrep bzgrep string files | ||
51 | for csh: (setenv GREP fgrep; bzgrep string files) | ||
52 | .SH AUTHOR | ||
53 | Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe | ||
54 | Troin <phil@fifi.org> for Debian GNU/Linux. | ||
55 | .SH "SEE ALSO" | ||
56 | grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1) | ||