Visit Our UNIX and Linux User Community


Unzip file By checking condition.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unzip file By checking condition.
# 1  
Old 03-03-2010
Bug 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.

Code:
$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
# 2  
Old 03-03-2010
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
# 3  
Old 03-03-2010
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.
# 4  
Old 03-03-2010
You try the following code.
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


Last edited by vivekraj; 03-03-2010 at 04:16 AM..

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip the .zip file without using unzip utility in UNIX

I have .zip file, i want to list all the files archived in the zip file. unzip utility is not working for me in unix. Please help me resolve this issue Thanks ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

2. Shell Programming and Scripting

Condition checking issue while if

hi, i am using a simple condition end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF select description from bravo_statistics where trunc(time_stamp)=trunc(sysdate)-1 and description='END CAT'; EOF` echo $end_ct; echo... (30 Replies)
Discussion started by: lovelysethii
30 Replies

3. Shell Programming and Scripting

Condition checking in UNIX

i have a script where i have to find the age of a file, if then echo "dnb file is present for the monthly load" >> $RUNLOG dnb="1" else echo "dnb file has not arrived yet" > $ERRLOG dnb="0" fi i know the file is available so... (3 Replies)
Discussion started by: lovelysethii
3 Replies

4. Shell Programming and Scripting

Checking file existence along with condition

Hi am trying to write a script which find the existence of a file from a find command output and perform a task if the file exists. Help me out with the correct syntax . Am trying with the following one but unable to get the output. if then <some tasks> else echo "file not exists" fi (5 Replies)
Discussion started by: rogerben
5 Replies

5. Shell Programming and Scripting

create separate file after checking condition..

Problem : I want to create a separate file for country list if condition is true. Please help. ***************************************************** Input file: SV-INCR-139302-365540488-201104090934.sqllog SV-INCR-1082-552793184-201104040805.sqllog SV-INCR-1077-855045741-201104040805.sqllog... (4 Replies)
Discussion started by: humaemo
4 Replies

6. Shell Programming and Scripting

Cutting specific line of a file by checking condition

testfile.csv 0","1125209",,"689202CBx18888",,"49",,,"NONMC",,,,,"01112010",,,,,,,"MTM- "1","",,"689202ABx19005",,"49",,,"NONMC",,,,,"01072010",,,,,,,"MTM- testfile.csv looks like above format if the second column is null then get 23rd column and store in a different varible .. add all the... (1 Reply)
Discussion started by: mgant
1 Replies

7. Shell Programming and Scripting

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

8. Shell Programming and Scripting

Checking condition inside the loop

Hi all, I have one clarification i am using the loop which will process for each record .suppose there is f ailure in the first record it need to send mail and process the next .my code: defcount=`cat <filename>|wc -l` while ] do if <some condiotion> then echo "mail" fi done so... (1 Reply)
Discussion started by: ithirak17
1 Replies

9. HP-UX

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

10. Shell Programming and Scripting

Condition checking

Dear all That's another problem from me, i wanna do a lot of if statement checking for correct input by user, will be prompt input again if the input not meet the requirement defined by If or while statement... like this one .... while I know it's less effiency write the program... (14 Replies)
Discussion started by: trynew
14 Replies

Featured Tech Videos