Visit Our UNIX and Linux User Community


Single command - unzip files from a tar command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Single command - unzip files from a tar command
# 1  
Old 04-03-2012
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)
# 2  
Old 04-03-2012
Code:
tar xvf a.tar | xargs gzip -d

# 3  
Old 04-03-2012
Hi try this one Smilie
Code:
tar xvfz a.tar.gz

Thanks,
Senthil
# 4  
Old 04-03-2012
Quote:
Originally Posted by balajesuri
Code:
tar xvf a.tar | xargs gzip -d

This "almost" works. But somehow there is a .gz appended to the file name which makes it fail. How to tweak it?
======================================
Code:
#  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


Last edited by Franklin52; 04-03-2012 at 11:40 AM.. Reason: Please use code tags for data and code samples, thank you
# 5  
Old 04-03-2012
From the looks of that output not all of the tarball is compress files?

Maybe something like:
Code:
tar xvf a.tar | grep '.Z$' | xargs gzip -d -S ""

# 6  
Old 04-03-2012
Quote:
Originally Posted by CarloM
From the looks of that output not all of the tarball is compress files?

Maybe something like:
Code:
tar xvf a.tar | grep '.Z$' | xargs gzip -d -S ""

This is the output for tar xvf a.tar
Code:
# 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.
Code:
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?
Code:
# 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


Last edited by Franklin52; 04-03-2012 at 11:41 AM.. Reason: Please use code tags for data and code samples, thank you
# 7  
Old 04-03-2012
try this...

use awk, if you dont have nawk

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


Previous Thread | Next Thread
Test Your Knowledge in Computers #80
Difficulty: Easy
Many operating systems today, including Android, Chrome OS, Steam OS, and myriad embedded systems for devices, are based on Linux.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tar and unzip on single command

Hi All, First of all I don't know whether this is possible. or no. Thought of getting experts thought. I am having a tar file which contains zipped file in it . I tried individual command with extraction and it worked tar -tvf TRANS_279.tar -rw-rw-r-- qqa00 1394 2016-10-03 10:39:19... (8 Replies)
Discussion started by: arunkumar_mca
8 Replies

2. UNIX for Dummies Questions & Answers

7z command for files larger than 4GB ( unzip doesn't work)

My unzip command doesn't work for files that are greater than 4GB. Consider my file name is unzip -p -a filename.zip, the command doesn't work since the size of the file is larger. I need to know the corresponding 7z command for the same. This is my Unix shell script program: if then ... (14 Replies)
Discussion started by: chandraprakash
14 Replies

3. Shell Programming and Scripting

Extract a list of files using unzip command

Hi all, this is my first and i can't speak english well, so please be kind ! Here is my problem : I want to unzip a list of .zip files stored in one directory, so I though about using that : unzip '*.zip' Thing is that all of my zipped folders contain a file with the unique same name :... (6 Replies)
Discussion started by: remissssss
6 Replies

4. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

5. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

6. Linux

Unzip selected files in .tar.gz file

Hi All, By accident, i deleted some files. Fortunately I have a backup backup.tar.gz files (750GB). It's too big for me to untar to get the file Is it possible that i could get the selected files in backup.tar.gz if i know exactly where the files are located. Thanks. Ken (1 Reply)
Discussion started by: trongkhuongsg
1 Replies

7. Shell Programming and Scripting

Modifying command for Tar.gz Files.

:) Hi, I use the following command to search for a string in all the files in the directories and sub directories. find . -type f -print | xargs grep bermun@cial.net Can someone please cite a method wherin I can find the entries from a list of 300-500 *.gz files by modifying the above... (2 Replies)
Discussion started by: openspark
2 Replies

8. UNIX for Dummies Questions & Answers

tar command help -- extract single file

Hi, I want to view/display the contents of one file in tar file. For example if the tar file is sam.tar.gz and one of the file inside is E1.txt, how do i view the contents of this E1.txt file. Olso if I want to extract the E1.txt file only from sam.tar.gz how can i do that. Thanks in... (7 Replies)
Discussion started by: icefish
7 Replies

9. UNIX for Advanced & Expert Users

how to unzip and extract tar file in single command

In order to save diskspace and avoid of disk full during unzip then extract the tar file is there any tar unzip command would unzip and extract tar at the same time (test123.tar.gz) thank in advance (6 Replies)
Discussion started by: darkrainbow
6 Replies

10. UNIX for Dummies Questions & Answers

using tar command to copy files?

hi, can i use the tar command to copy an entire directory and its content in another folder? What is the proper syntax? thx (2 Replies)
Discussion started by: tomapam
2 Replies

Featured Tech Videos