Tar and unzip on single command

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Tar and unzip on single command
# 1  
Old 06-16-2017
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

Code:
tar -tvf TRANS_279.tar
-rw-rw-r-- qqa00 1394 2016-10-03 10:39:19 M9999_406.dat.zip
-rw-rw-r-- qqa00 142428 2016-10-03 10:43:58 P9999_406.dat.zip
-rw-rw-r-- qqa00  5504 2016-10-03 10:44:11 T9999_406.dat.zip

I want do unzip -l on the out of tar -tvf and see what are the files in it. Is that is possible which out extracting the tar

Thanks
Arun
# 2  
Old 06-16-2017
Hi,
with gnu tar, you have option "--to-commande=COMMANDE", so you can try:
Code:
tar --to-commande="unzip -l" -xf TRANS_279.tar

Regards.
These 4 Users Gave Thanks to disedorgue For This Post:
# 3  
Old 06-16-2017
disedorgue's locale may have added a trailing "e"
to --to-commande.

Your locale may not support that. We have some linux boxes that are set to Spanish.
On those boxes, I mess up the spelling of some options/filenames for commands all the time, because I type without thinking.
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 06-16-2017
I think I made the mistake when I copied it by hand the test I made from another workstation.

Thanks.

---------- Post updated at 09:11 PM ---------- Previous update was at 07:24 PM ----------

I'm very confused, but not work with unzip because not supported stdin stream, just file Smilie
# 5  
Old 06-16-2017
zip files unfortunately don't stream well. They've got a table of contents and do lots of seeking around. You might have funzip, which can extract the first file from a zip via pipe, but only the first file.
# 6  
Old 06-16-2017
We can replace unzip by script perl, like this script to show only file name in zip archive:
Code:
$ unzip -l f1.zip 
Archive:  f1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      283  2017-06-17 01:54   fich1.txt
      204  2017-06-17 01:54   fich2.txt
---------                     -------
      487                     2 files

Code:
$ unzip -l f2.zip 
Archive:  f2.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      487  2017-06-17 01:55   fich3.txt
      974  2017-06-17 01:56   fich4.txt
---------                     -------
     1461                     2 files

Code:
$ tar tf arch.tar 
f1.zip
f2.zip

Code:
$ tar xf arch.tar -O | perl ./unziplist.pl 
fich1.txt
fich2.txt
fich3.txt
fich4.txt

or
Code:
$ tar xf arch.tar --to-command="perl ./unziplist.pl"
fich1.txt
fich2.txt
fich3.txt
fich4.txt

Perl script code:
Code:
#!/usr/bin/env perl

use strict;
use warnings;
use IO::Uncompress::Unzip qw(unzip $UnzipError) ;

my $status=1;
my $z = new IO::Uncompress::Unzip "-"
	or die "IO::Uncompress::Unzip failed: $UnzipError\n";

$status = $z->nextStream() while $status;
my @hdrs = $z->getHeaderInfo();

for (@hdrs) { print $$_{"Name"}."\n"; }

EDIT: perl script more short:
Code:
#!/usr/bin/env perl

use strict;
use warnings;
use IO::Uncompress::Unzip qw($UnzipError) ;

my $z = new IO::Uncompress::Unzip "-"
    or die "IO::Uncompress::Unzip failed: $UnzipError\n";

do { print $z->getHeaderInfo()->{"Name"}."\n" } while $z->nextStream();

Regards.

Last edited by disedorgue; 06-17-2017 at 12:37 PM.. Reason: add more short perl script
# 7  
Old 06-16-2017
Quote:
Originally Posted by arunkumar_mca
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

Code:
tar -tvf TRANS_279.tar
-rw-rw-r-- qqa00 1394 2016-10-03 10:39:19 M9999_406.dat.zip
-rw-rw-r-- qqa00 142428 2016-10-03 10:43:58 P9999_406.dat.zip
-rw-rw-r-- qqa00  5504 2016-10-03 10:44:11 T9999_406.dat.zip

I want do unzip -l on the out of tar -tvf and see what are the files in it. Is that is possible which out extracting the tar

Thanks
Arun
Hi arunkumar_mca,

The answer to your question, unfortunately, is no. It is not possible to know the content of the zip files without untarring them first. Regardless of other suggestions.
The tar -tvf will present to you a list of the content in the tar, but that's a list only, not the actual zip file and unzip -l does need to have the zip file to tell you what its content is. Therefore, the only way is to untar (extract the tar) first. And then let unzip -l read the content of it and report to you.
This User Gave Thanks to Aia For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to supress output from tar and unzip commands?

I have the below two commands in my script. tar -xf hello.tar unzip -o tempp.zip When i run the script i see the below on my standard out. How can i suppress output coming from both the tar and unzip on my standard output. (3 Replies)
Discussion started by: mohtashims
3 Replies

2. UNIX for Dummies Questions & Answers

Extract .zip file without using unzip,tar

Hi, Need to extract a file containing multiple .txt files without using tar/unzip as they are not available (1 Reply)
Discussion started by: santoshdrkr
1 Replies

3. Shell Programming and Scripting

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) (9 Replies)
Discussion started by: ericlim
9 Replies

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

5. Shell Programming and Scripting

unzip single file and untar single file

Dear friends, My requirement below- 1] I have a zip file on unix server - ETL_Extracts_20100218175009.zip which is composed of various entity extracts namely... ENTITY1.txt, ENTITY2.txt, ENTITY3.txt etc.... How do I unzip only a single file ..say ENTITY2.txt from this zip file. CAn you... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

6. AIX

how to unzip wget-latest.tar.gz

I download wget-latest.tar.gz from Index of /gnu/wget, however, it saved in my windows as wget-latest.tar.tar After I ftp it to aix server, #file wget-latest.tar.tar wget-latest.tar.tar: data or International Language text how to uzip it? ---------- Post updated at 04:13 PM ----------... (3 Replies)
Discussion started by: rainbow_bean
3 Replies

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

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 Desktop Questions & Answers

file zip,rar,tar,compress,uncompress,unzip,unrar

i want know how to compress and uncompress file using unix, compress uncompress,zip,unzip,rar,unrar,how its work and more about this.:confused: (1 Reply)
Discussion started by: ismael xavier
1 Replies

10. 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
Login or Register to Ask a Question