Elegant gunzip of tar Contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Elegant gunzip of tar Contents
# 1  
Old 11-21-2008
Elegant gunzip of tar Contents

I am faced with a situation where I have directories of gunzipped contents bundled into a tar file. It might look something like this.
x coop/batch/bin/ha90x20.gz, 632641 bytes, 1236 tape blocks
x coop/batch/icm/HA90X20.icm.gz, 1821 bytes, 4 tape blocks
x coop/batch/aeenv.gz, 4117 bytes, 9 tape blocks
x lib/libiclm.a.gz, 5998416 bytes, 11716 tape blocks
x lib/libiclm.sl.gz, 5260938 bytes, 10276 tape blocks
x lib/libime.a.gz, 5816597 bytes, 11361 tape blocks
x lib/libime.sl.gz, 4856468 bytes, 9486 tape blocks
x lib/libimisc.a.gz, 5497949 bytes, 10739 tape blocks
x lib/libimisc.sl.gz, 4591464 bytes, 8968 tape blocks
x lib/libipc.a.gz, 1250457 bytes, 2443 tape blocks
x lib/libipc.sl.gz, 1102578 bytes, 2154 tape blocks
x lib/libipr.a.gz, 5148901 bytes, 10057 tape blocks
x lib/libipr.sl.gz, 4334738 bytes, 8467 tape blocks
This is a small sample, we always have quite a bit more that could be completely different files. Anyway, we have always done a "tar xvf" on the tar files, followed by a find and gunzip of all files that are gunzipped. A problem has arose where there are files that already exist that the customer has gzipped. Is there an elegant way I can pipe the contents of the tar files through gunzip so that I only gunzip the contents of the tar file all in one fell swoop.

I have tried something like this but the gunzip never executes, I receive no errors, it just does not seem to execute.
ls *.tar | while read tarfilename
do
tar xvf ${tarfilename} |awk '{print $2}' |sed 's/,//g' |xargs -i gunzip -fdrv {}
done

I am on HPUX. I am leaning toward the need to write the output of the tar command to a file and work from that, but why can I not use that output on the fly? Thanks in advance.
# 2  
Old 11-21-2008
Quote:
I am on HPUX. I am leaning toward the need to write the output of the tar command to a file and work from that, but why can I not use that output on the fly? Thanks in advance.
...

Now I know why Im not going to change my way of working:
Make a tar file first then gzip
using it is:
gzcat <tarfile>.tar.gz |tar -tvf - (or xvf...)
# 3  
Old 12-02-2008
Thanks But

Quote:
Originally Posted by vbe
...

Now I know why Im not going to change my way of working:
Make a tar file first then gzip
using it is:
gzcat <tarfile>.tar.gz |tar -tvf - (or xvf...)
Normally this is how I work as well. But there were space constraints on the server where they did not have room to create the tar file first without first gzipping all the files.

Anyway, I found a solution and thought I would post my findings if someone faces a similar situation. Seems tar's output is standard error rather than standard out. Notice the change to how I am piping the output.

ls *.tar | while read tarfilename
do
tar xvf ${tarfilename} 2>&1| awk '{print $2}' |sed 's/,//g' |xargs -i gunzip -fdrv {}
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Listing contents of .tar.gz files

Hi All, I would like to know couple of ways to list the content available in tar and gzipped file without extracting. i.e., I would like to display the contents of test.tar.gz without extracting. Note :: please suggest a command other that tar -ztvf (9 Replies)
Discussion started by: Girish19
9 Replies

2. UNIX for Dummies Questions & Answers

Gunzip and tar command

Hi I wanted to tar and gunzip a file named backup tar: backup.tar: Wrote only 2244 of 10240 bytes tar: Error is not recoverable: exiting now Please tell me what I am doing wrong? Please do help. (4 Replies)
Discussion started by: sonia102
4 Replies

3. AIX

Gunzip tar A directory checksum error on media

Hi, what is the directory checksum error ? # sed 's/^M$//' test4_bkp_19Jan13.tgz | tar -tvf - tar: 0511-169 A directory checksum error on media; -265745505 not equal to 76225. # mv test4_bkp_19Jan13.tgz test4.gz # gunzip < /ebs2/test4.gz | tar -xvf - tar: 0511-169 A directory checksum... (4 Replies)
Discussion started by: filosophizer
4 Replies

4. Shell Programming and Scripting

Extract contents of tar ball without extracting files

Hi, I'm using a tar command tar -xOvf /home/mytar.tar My intention is to extract data in files which are inside various directories, without extracting files to the disk. Is this the best way to achieve it? Thanks, Chetan (3 Replies)
Discussion started by: chetan.c
3 Replies

5. Shell Programming and Scripting

How to grep the contents inside a tar file

Hi All I have searched the possibility of this options everywhere but am unable to find it in any forum. I have a tar file inside which there are n number of files and i dont know them. I need to grep a word inside the tar file and need to know in which file the word resides. > cat a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

6. Solaris

Listing Contents of tar.gz file

Hi fellows, Can you please share any command with which I can list down the file names inside a tar.gz file. I have tried with these possibilities but in vain. bash-3.00$ tar -ztvf file.tar.gz tar: z: unknown function modifier bash-3.00$ tar ztvf file.tar.gz tar: z: unknown function... (1 Reply)
Discussion started by: Zaib
1 Replies

7. AIX

how to take tar backup of the contents of a file

Hi I have a file named files.2.backup which holds the location of some directory and file i,e $ cat files.2.backup /d01/app/oracle/product/7.3.2/dbs/fortest_syst_01.dbf /d01/app/oracle/product/7.3.2/dbs/fortest_temp_01.dbf /d01/app/oracle/product/7.3.2/dbs/fortestdata_01.dbf... (5 Replies)
Discussion started by: sumanbangladesh
5 Replies

8. Shell Programming and Scripting

Retaining tar.gz after gunzip

gunzip fnam.tar.gz After this command execution... .gz file no longer exists... and only fnam.tar is present. Is it possible to retain the tar.gz file after after using the above command thx in advance. (4 Replies)
Discussion started by: devs
4 Replies

9. Shell Programming and Scripting

Tar and gunzip piping

I am using IRIX 6.5.11 and tcsh. I have created an arcihive by using the command "tar -cvf - /stuff/ /more/stuff|gzip --best>/stuff.tar.gz" It made an archive of my files without taking up huge amounts of disk space with uncompressed files. How do I extract files from the archive without... (2 Replies)
Discussion started by: madyodacolon
2 Replies

10. Solaris

Combination of gunzip and tar on Solaris

Hello I'm trying to use a combination of gunzip and tar to unpack and unzip a *.tar.gz file. I tried gunzip ~/myfile.tar.gz | gtar -x This will unzip the file, but it won't unpack. Any hints? thanks a lot Dan (5 Replies)
Discussion started by: dwidmer
5 Replies
Login or Register to Ask a Question