Unzip file By checking condition.

Hi.. Gurus

I Have a list of .zip files in a directory. I want to check whether each .zip file having some particular file or not (say .jsp) if it's having .Jsp file then create a directory as per the .zip file and extract the content to that directory except the .jsp file, If .zip not having .jsp then no action.

$cat /tmp/sample
aaa.zip
bbb.zip
ccc.zip

Lets aaa.zip files having aa.js,aa.txt,aa.gif
bbb.zip files having bb.txt,bb.gif
ccc.zip files having cc.jsp,cc.txt,cc.gif,cc.csv
As the aaa.zip and ccc.zip having aa.jsp and cc.jsp for these two file we are going to create a directory as per there name called /tmp/aaa and /tmp/ccc and it should contain aa.txt,aa.gif and cc.txt,cc.gif,cc.csv respectively.

Thank & Regard's
Posix

i think it cant be, posix...
firstly, you must unzip the zip files.
til now, i never know that shell script can check the file inside zip files.....
CMIIW

What do you have so far? What problems have you encountered.

On a more general note, if you've got a question, please don't state it as if you've got a requirement and are handing it down to us, as we're not here to do your work.

You try the following code.

 
while read line 
do 
if [[ -e $line ]];then 
mkdir temp 
cp $line temp 
cd temp 
unzip $line 
cd - 
if [[ -n `ls temp | grep .jsp` ]];then 
line1=`ls temp | grep -v ".jsp\|.zip"` 
for i in $line1 do dir=`echo /tmp/``echo $line | cut -d '.' -f 1`
if [[ -d $dir ]]; then 
cp temp/$i $dir 
else 
mkdir $dir 
cp temp/$i $dir 
fi 
done 
fi 
fi 
rm -rf temp 
done < zipfile 
rm -rf temp