How to unzip files from the same folder?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to unzip files from the same folder?
# 1  
Old 07-19-2011
How to unzip files from the same folder?

Hi ,
I have two ear files in a single folder. the ear file contains same xml files named "File1.xml". how to unzip each file seperately using shell script?

Thanks,
Chella.
# 2  
Old 07-19-2011
Code:
unzip -d

# 3  
Old 07-19-2011
try with below code
Code:
for i in `ls -l *.ear | awk '{print $NF}'`
do
jar xvf $i
done

In case you want to give the filename at run-time then try below code

test.sh 1.ear

Code:
jar xvf $1

Cheers
Harish
# 4  
Old 07-19-2011
hi , thanks for your reply..
Actually i have two ear files
ex: a.ear
b.ear
if i unzip the a.ear it contains File1.xml . and the same file1.xml is in the b.ear files with different contents.
I want to extract the files one by one and read some values from the File1.xml. Can we do it in shell script??? Please help me......
# 5  
Old 07-19-2011
Code:
 
for i in *.ear
do
    jar xvf $i
    #read your File.xml here
    #once read is completed, just delete it.
done

# 6  
Old 07-19-2011
In below case I am just viewing both the file1.xml i.e in a.ear and b.ear
If you want you can also edit them

a.ear file1.xml

Code:
this is a.ear file1.xml

b.ear file1.xml

Code:
this is b.ear file1.xml

test.sh

Code:
for i in `ls -l *.ear | awk '{print $NF}'`
do
filename=`jar xvf $i | awk -F ":" '{print $2}'`
if [ $filename = file1.xml ]; then
cat $filename
fi
done

output

Code:
this is a.ear file1.xml
this is b.ear file1.xml

Cheers
Harish
# 7  
Old 07-19-2011
Hi Harish,
Thanks for your reply. I try that code. But its not working.
I will clearly provide my requirement.

I have two ear files
service1.ear
service2.ear

each ear contains credentials.xml (both ear contains the same filename i.e credentials.xml)

I want to unzip "service1.ear" then I will open the "credentials.xml" and take some values. after that I need to open "service2.ear" and do the same thing. I need this requirement in shell script format.. Just give the syntax. I will make it for my as per my requirement.

Thanks you so much....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

4. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

5. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

6. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

7. Shell Programming and Scripting

Unzip folder on remote machine

Hi ! I am trying to automate FTP transfer of some folders from one unix machine (a) to another one (b). I run my shell script on machine a. The problem I face is how to unzip the folder at the machine b with script run in machine a. My first question: Is there any way to do this ? My... (10 Replies)
Discussion started by: siba
10 Replies

8. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

9. UNIX for Dummies Questions & Answers

unzip files in a different folder

hi , I am using this command to unzip files from a source unzip -o $source_dir -d $dest_dir butthe problem is that this command creates a new folder at the destination and unzips all the files in that folder. I dont want that extra folder. e.g source_dir= abc/myname.zip... (2 Replies)
Discussion started by: agarwalniru
2 Replies

10. Shell Programming and Scripting

unzip particular gzip files among the normal data files

Hello experts, I run Solaris 9. I have a below script which is used for gunzip the thousand files from a directory. ---- #!/usr/bin/sh cd /home/thousands/gzipfiles/ for i in `ls -1` do gunzip -c $i > /path/to/file/$i done ---- In my SAME directory there thousand of GZIP file and also... (4 Replies)
Discussion started by: thepurple
4 Replies
Login or Register to Ask a Question