#!/bin/bash
# find in files
if [ $# -eq 0 ]; then echo "usage: $0 \"
\" \"\" \"\" \"\" [-verbose]"; exit 1; fi
dirs=$1;
zippattern=$2;
filepattern=$3;
searches=$4;
option=$5;
tmpdir=`mktemp -d`; rm -fr $tmpdir;
cnt=0;
for d in $dirs; do
tmp=$(mktemp -p /tmp XXXXXX); rm -f $tmp; tmp="_"${tmp//\//}${tmp//\//}tmp"_"; # echo $tmp; # make random string (YY6Qjj), then change to _tmpYY6QjjtmpYY6Qjjtmp_
zips=$(find $d -type f -name "$zippattern" | sed -e "s/ /$tmp/g"); # echo $files; # get zipfiles and apply temp string replacement for " " to keep files w/ spaces in names together
for z in $zips; do
unzip -q -d $tmpdir $z;
files=$(find $tmpdir -type f -name "$filepattern" | sed -e "s/ /$tmp/g"); # echo $files; # get files and apply temp string replacement for " " to keep files w/ spaces in names together
for f in $files; do
g=${f#$tmpdir/}; #echo "$g ..."; # remove temp string replacement for " "
if [ "$(egrep -c "$searches" "$f")" != "0" ]; then
(( cnt++ ));
echo "** [$cnt] $z!$g ** " | grep $g;
if [ "$option" = "-V" ] || [ "$option" = "-verbose" ]; then
egrep -n -B2 -A2 "$searches" "$f";
echo "";
fi
fi
done
rm -fr $tmpdir
done
done