The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk: need to extract a line before a pattern npn35 Shell Programming and Scripting 17 06-29-2008 10:38 PM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 11:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 04:44 AM
Extract the Pattern aajan UNIX for Dummies Questions & Answers 6 08-08-2007 04:47 AM
Please help! Sed extract a pattern zhen Shell Programming and Scripting 11 09-18-2006 12:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-16-2008
percivalwcy percivalwcy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
Extract .tgz files that only contain a pattern

Let's say I've got File.tgz that contains:-

Apple.txt
Banana.txt
Carrot.txt
AppleBanana.txt

Now, I would like to only extract files that contain the patter "Apple".

I've tried this

tar -xvf File.tgz 'tar -tf File.tgz | grep 'Apple''

but it does not work. Please help. Thanks.
  #2 (permalink)  
Old 08-16-2008
Vi-Curious Vi-Curious is offline
Registered User
  
 

Join Date: Jul 2008
Location: Texas
Posts: 129
Code:
 
gunzip < File.tgz | tar xvf - Apple.txt AppleBanana.txt
  #3 (permalink)  
Old 08-16-2008
percivalwcy percivalwcy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
Hi Vi-Curious. Your code does work, but not exactly what I was looking for. On most occasions, I don't know the exact filename inside the .tgz file to extract. Hence, the grep.

It's taking me days, and I still have not figured it out. Please help. Thanks.
  #4 (permalink)  
Old 08-16-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
gunzip < File.tgz |grep 'Apple'|xargs tar xvf -
i am not sure about this try and see.....
  #5 (permalink)  
Old 08-16-2008
Vi-Curious Vi-Curious is offline
Registered User
  
 

Join Date: Jul 2008
Location: Texas
Posts: 129
I don't know how it could be done with a single command. The best I can give you is this:

Code:
 
gunzip < File.tgz | tar tf - | grep Apple > extract
gunzip < File.tgz | tar xvf - -I extract
  #6 (permalink)  
Old 08-17-2008
percivalwcy percivalwcy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
Thanks Vi-Curious. For now, I think I shall use multiple lines to do what I want. Thanks so much!
  #7 (permalink)  
Old 08-17-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
I think what you originally had in mind would have been something like this:

Code:
tar -xvf File.tgz `tar -tf File.tgz | grep 'Apple'`
Note those are back (grave) quotes (ASCII 96) not regular quotes.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0