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
# 8  
Old 08-17-2008
Oh yes!!!! It works!!!! Thanks so much era. Thanks so much everybody!!!!
# 9  
Old 08-17-2008
Quote:
Originally Posted by era
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.

On my system, tar won't open zipped tar files.
# 10  
Old 08-17-2008
Yes, Vi-Curious. I can't open zipped tar files as well. That potentially is a problem because I sometimes also want to extract zip files as well. Is there any option so that we can unzip the zip files also, including the tgz files?
# 11  
Old 08-18-2008
I don't understand. I thought you said that era's solution worked??? The file extension tgz is supposed to be a zipped tar file. So how do you say his solution worked and then say you can't open zipped tar files?
# 12  
Old 08-18-2008
Hi Vi-Curious. Sorry, what I meant it does not work for files like Files.tgz.zip. I thought that was what you meant when you said "zipped tar files". In this case, the command does not work. It works fine for .tgz files.
Sorry for the confusion.

So, what errors do you get when you run the below command?
tar -xvf File.tgz `tar -tf File.tgz | grep 'Apple'`


Thanks.
# 13  
Old 08-18-2008
That's slightly inexact. tar by itself simply collects stuff into a container; usually, this file has an extension .tar and very often, you then compress ("zip") it using gzip or bzip2. This is different from the Windows program zip/unzip which does both jobs (collecting into a container, and compressing). A gzipped tar file gets an extension of .tar.gz or .tgz (for legacy DOS compatibility) and a bzipped tar file usually gets .tar.bz2. There was also a legacy utility compress which had the extension .Z and those were mapped into .taz for DOS compatibility, but you don't see it used much these days, as the compression rate is unimpressive by today's standards.

(Of course, the extension could basically be anything or nothing, but these are the usual conventions.)

Some modern tar programs have options to do compression and decompression on the fly; in GNU tar, the z flag selects gzip compression and decompression, and the j flag selects bzip2.
 
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