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.

unzip -d 

try with below 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

jar xvf $1

Cheers
Harish

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......

 
for i in *.ear
do
    jar xvf $i
    #read your File.xml here
    #once read is completed, just delete it.
done

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

this is a.ear file1.xml

b.ear file1.xml

this is b.ear file1.xml

test.sh

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

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

Cheers
Harish

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....

did u try my code ?

yes, kamaraj.. it is also not worked.... :frowning:

what is not worked ?
what you tried... post the code, so that i can help u

Hi Kamaraj,
Its running. But it will stuck like below:

Archive: CommonPaymentServices_1.ear
inflating: Shared Archive.sar
inflating: TIBCO.xml
inflating: Process Archive.par

the ear file contains the above files...

after that i dint get the prompt symbal. I need to use control+C then come out form the script.

And also I need to do this for more than two files. and i have already explained in my previous reply...

Thanks in advance....

That's a really inefficient and error-prone way to do pathname expansion (file glob). Aside from having to create a pipeline, any whitespace will break the code (in which case $NF will contain only a portion of the filename). Just use the shell's standard features to do that, quote "$i" every time you use it, and you'll be iterating through matching filenames in a safe manner.

for i in *.ear; do
    # Whatever processing needs to be done on "$i"
done

Regards,
Alister