If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > tar and gzip question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-08, 20:48
brianr8011 brianr8011 is offline
Registered User
 
Join Date: Sep 2007
Posts: 6
tar and gzip question

Hello again!

I have a file filename.tar.gz. I would like to see a list of the files in the tarball as well as the number of lines in each file.

I know wc -l will give me the number of lines in a file.
I know that tar -t will give me a list of the files in a tarball.
I know that gzcat will show me the contents of a compressed file without uncompressing it.

My first attempt was
Code:
gzcat filename.tar.gz | tar -t | wc -l
but that isn't right....

What I'm having problems with is putting these commands together to produce the desired result. Are these even the best commands to use? Is there a better (easier) way?

Any help would be appreciated.

Thanks,
Brian
Reply With Quote
  #2 (permalink)  
Old 09-04-08, 02:43
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
you need -f with tar
gzcat filename.tar.gz | tar -tf - | wc -l
or with gnu tar
tar -tzf filename.tar.gz | wc -l
Reply With Quote
  #3 (permalink)  
Old 09-04-08, 04:42
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
This will give you a count of files because it operates on the output of "tar -tzf".

If you want to have the line count of each file, you will have to untar the archive and then scan on the files.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 09-04-08, 09:01
brianr8011 brianr8011 is offline
Registered User
 
Join Date: Sep 2007
Posts: 6
Thanks for the quick responses guys.

Maybe a list of the files will be sufficient for what my user is requesting. I'm not sure if he will want to untar the archive or not, but I'll present him with the facts you've given and let him decide how to proceed.

Thanks again.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On