Single command - unzip files from a tar command

I have a tar file that contains multiple .Z files. Hence I need to issue a tar command followed by a gzip command to fully extract the files. How do I do it in a single command?

What I'm doing now is
tar xvf a.tar (this will output 1.Z and 2.Z)
gzip -d *.Z (to extract 1.Z and 2.Z)

tar xvf a.tar | xargs gzip -d

Hi try this one :slight_smile:

tar xvfz a.tar.gz

Thanks,
Senthil

This "almost" works. But somehow there is a .gz appended to the file name which makes it fail. How to tweak it?

#  tar xvf a.tar | xargs gzip -d
x.gz: No such file or directory
RET20120101.dat.Z,.gz: No such file or directory
939194.gz: No such file or directory
bytes,.gz: No such file or directory
1835.gz: No such file or directory
media.gz: No such file or directory
blocks..gz: No such file or directory
x.gz: No such file or directory
RET20120102.dat.Z,.gz: No such file or directory
939194.gz: No such file or directory
bytes,.gz: No such file or directory
1835.gz: No such file or directory
media.gz: No such file or directory
blocks..gz: No such file or directory

From the looks of that output not all of the tarball is compress files?

Maybe something like:

tar xvf a.tar | grep '.Z$' | xargs gzip -d -S ""

This is the output for tar xvf a.tar

# tar xvf a.tar
x RET20120101.dat.Z, 939194 bytes, 1835 media blocks.
x RET20120102.dat.Z, 939194 bytes, 1835 media blocks.

If I do below, there is no ouput.

tar xvf a.tar | grep '.Z$'

If I do below, it's almost there but the extra , after the .Z is causing problem. Any suggestion how to get it right?

# tar xvf a.tar | grep '.Z'  | xargs gzip -d -S ""
x: No such file or directory
RET20120101.dat.Z,: No such file or directory
939194: No such file or directory
bytes,: No such file or directory
1835: No such file or directory
media: No such file or directory
blocks.: No such file or directory
x: No such file or directory
RET20120102.dat.Z,: No such file or directory
939194: No such file or directory
bytes,: No such file or directory
1835: No such file or directory
media: No such file or directory
blocks.: No such file or directory

try this...

use awk, if you dont have nawk

 
tar xvf a.tar | nawk -F"[ ,]" '$2~/Z$/{print $2}' | xargs gzip -d -S ""

Thanks a lot!!! The below gets me the result I needed.

tar xvf a.tar | nawk -F"[ ,]" '$2~/Z$/{print $2}' | xargs gzip -d

I too have a doubt regarding the unzipping of the files.. I have a file named logfiles_tar.tgz under my log directory..At the end of the day all of the logs gets zipped to this particular file. If i want to unzip all the files, what am gonna do?

Thanks

Hello,

Please do not ask new questions in existing threads. Unless you have new information to a particular problem, please create a new thread in the appropriate forum.

Also, please search the forums first, as it might be that someone has already posted an answer for a similar problem.

Best regards,
The UNIX and Linux Forums