~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to zip/unzip/unix/zipgrep

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

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
 
for i in `unzip -Z1 "$zipfile" ${1+"$@"}`; do
42
 
  if test $list -eq 1; then
43
 
 
44
 
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" > /dev/null && echo $i
45
 
    r=$?
46
 
  elif test $silent -eq 1; then
47
 
 
48
 
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat"
49
 
    r=$?
50
 
  else
51
 
    unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" | sed "s|^|${i}:|"
52
 
    r=$?
53
 
  fi
54
 
  test "$r" -ne 0 && res="$r"
55
 
done
56
 
exit $res