Extract .tgz files that only contain a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract .tgz files that only contain a pattern
# 1  
Old 08-16-2008
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  
Old 08-16-2008
Code:
 
gunzip < File.tgz | tar xvf - Apple.txt AppleBanana.txt

# 3  
Old 08-16-2008
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  
Old 08-16-2008
gunzip < File.tgz |grep 'Apple'|xargs tar xvf -
i am not sure about this try and see.....
# 5  
Old 08-16-2008
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  
Old 08-17-2008
Thanks Vi-Curious. For now, I think I shall use multiple lines to do what I want. Thanks so much!
# 7  
Old 08-17-2008
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Extract date from files based on file pattern

I want to extract dates from the files and i have different types of files with pattern. I have list file with the patterns and want to date extract based on it in a sh script Files in the directory : file1_20160101.txt file2_20160101_abc.txt filexyz20160101.txt list file with... (2 Replies)
Discussion started by: lijjumathew
2 Replies

3. Shell Programming and Scripting

Extracting specific files from multiple .tgz files

Hey, I have number of .tgz files and want to extract the file with the ending *results.txt from each one. I have tried for file in *.tgz; do tar --wildcards -zxf $file *results.txt; doneas well as list=$(ls *.tgz) for i in $list; do tar --wildcards -zxvf $i *.results.txt; done... (1 Reply)
Discussion started by: jfern
1 Replies

4. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

5. Shell Programming and Scripting

How to move files to existing .tgz file?

Hi, I have already created the tar files. which consist of some log files and Audit.csv plz see the below code for that ================================================ tar -Pczf ARCH/${arc_date}.tgz $LOG/*.log $REYE/CEP/FiAdapter/Audit.${arc_date}.csv ... (3 Replies)
Discussion started by: pspriyanka
3 Replies

6. UNIX for Advanced & Expert Users

how to grep/read a file inside compressed tgz without extract?

Hi all, I would like to ask whether in Unix shell/perl have any functions or command to allow grep/cat/read a file inside compressed .tgz without extract it? I know we can tar tvf a compressed tgz but this only allow we read the path/filename contained inside the tarball. If we want to read... (3 Replies)
Discussion started by: mayshy
3 Replies

7. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

8. UNIX for Dummies Questions & Answers

file.tgz.1of2 & file.tgz.2of2

Hi all, Need help. Anybody seen this kind of file before? file.tgz.1of2 file.tgz.2of2 how to extract this tgz file? Any help? Tq (5 Replies)
Discussion started by: zeedwolf
5 Replies

9. UNIX for Dummies Questions & Answers

Create individual tgz files from a set of files

Hello I have a ton of files in a directory of the format app.log.2008-04-04 I'd like to run a command that would archive each of these files as app.log.2008-04-04.tgz I tried a few combinations of find with xargs etc but no luck. Thanks Amit (4 Replies)
Discussion started by: amitg
4 Replies

10. UNIX for Dummies Questions & Answers

unzip .tgz files

hi all How to unzip .tgz files waiting for suggestions Praful (5 Replies)
Discussion started by: Prafulla
5 Replies
Login or Register to Ask a Question