~ubuntu-branches/ubuntu/precise/unzip/precise-proposed

« back to all changes in this revision

Viewing changes to unix/zipgrep

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2004-06-06 17:57:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040606175746-nl7p2dgp3aobyc2c
Tags: upstream-5.51
ImportĀ upstreamĀ versionĀ 5.51

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# zipgrep: searches the given zip members for a string or pattern
 
3
# This shell script assumes that you have installed UnZip.
 
4
 
 
5
pat=""
 
6
opt=""
 
7
while test $# -ne 0; do
 
8
  case "$1" in
 
9
  -e | -f) opt="$opt $1"; shift; pat="$1";;
 
10
  -*)      opt="$opt $1";;
 
11
   *)      if test -z "$pat"; then
 
12
             pat="$1"
 
13
           else
 
14
             break;
 
15
           fi;;
 
16
  esac
 
17
  shift
 
18
done
 
19
 
 
20
if test $# = 0; then
 
21
  echo "usage: `basename $0` [egrep_options] pattern zipfile [members...]"
 
22
  echo searches the given zip members for a string or pattern
 
23
  exit 1
 
24
fi
 
25
zipfile="$1"; shift
 
26
 
 
27
list=0
 
28
silent=0
 
29
opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
 
30
case "$opt" in
 
31
  *l*) list=1; opt=`echo $opt | sed s/l//`
 
32
esac
 
33
case "$opt" in
 
34
  *h*) silent=1
 
35
esac
 
36
if test -n "$opt"; then
 
37
  opt="-$opt"
 
38
fi
 
39
 
 
40
res=0
 
41
IFS='
 
42
'
 
43
for i in `unzip -Z1 "$zipfile" ${1+"$@"}`; do
 
44
  if test $list -eq 1; then
 
45
 
 
46
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" > /dev/null && echo $i
 
47
    r=$?
 
48
  elif test $silent -eq 1; then
 
49
 
 
50
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat"
 
51
    r=$?
 
52
  else
 
53
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" | sed "s|^|${i}:|"
 
54
    r=$?
 
55
  fi
 
56
  test "$r" -ne 0 && res="$r"
 
57
done
 
58
exit $res