Tar only files with a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tar only files with a pattern
# 1  
Old 12-09-2014
Tar only files with a pattern

Dear All,

I have a big tar.gz file with 210 files. About 60 of them have *.control.* pattern and I want only these.

Is there a way to extract only the files with this patter?

I tried zgrep with tar, but I am not having sucess.

Thanks, Leandro
# 2  
Old 12-09-2014
According to:
Code:
tar --help | grep excl

You should try this:
Code:
tar -axf "tarball.tar.gz" -X *.control.*

hth
This User Gave Thanks to sea For This Post:
# 3  
Old 12-09-2014
Dear Sea,

Thanks very much for your help!

But I got an error message:

tar: *.control.*: No such file or directory

I looked at tar --help | grep excl, but said that -X exclude patterns listed in FILE. Will it exclude the file with the pattern?

Thank you so much!
# 4  
Old 12-09-2014
Dear IColli

Have no practice with such a situation, but according to the error message part you posted, i'd try:
Code:
tar -axX *.control.* -f "tarball.tar.gz"

(i mis-aranged the syntax in prior post)

That is since I understand it like the pattern is to be search in the tarball FILE.
But now writing, actualy you want to exlcude everything else, but only 'include' *control*...

This said, i guess it would be easier (for later) to now extract everything, and make a new tarball only including those *.control.* files.

Hope this helps

---------- Post updated at 18:50 ---------- Previous update was at 18:47 ----------

HA... lol...
Even simpler...

Code:
tar -axf tarball.tar.gz *.control.*

sry
This User Gave Thanks to sea For This Post:
# 5  
Old 12-09-2014
tar -axf tarball.tar.gz *.control.*

Worked just perfect!!! SmilieSmilieSmilie

Thanks so much for your help!! SmilieSmilieSmilie
 
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 create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

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

3. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

4. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

5. UNIX for Dummies Questions & Answers

Tar everything matching a pattern

What's the best way to copy (and after I've confirmed it works ok, move) all files matching *.bak* (within an entire directory structure) into a single tar file? This is what I want to achieve, albeit the syntax is not correct: tar -cvf MigrationBAKFiles.tar (find . -name *.BAK*) Maybe I... (4 Replies)
Discussion started by: daveaasmith
4 Replies

6. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

7. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

8. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

9. UNIX for Dummies Questions & Answers

.tar.tar files

I downloaded what I thought was a gziped file (at least on remote server it had a .gz extention) and once I had it it was filename.tar.tar..I tried the standard untar tar -xvf filename on it and get an error. Does anyone know what's going on? (5 Replies)
Discussion started by: capeme
5 Replies

10. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies
Login or Register to Ask a Question