Grep through a .tar file without untarring it


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep through a .tar file without untarring it
# 1  
Old 02-16-2015
Grep through a .tar file without untarring it

Hi All,

I need to grep through a .tar file without untarring it. Would you please help me with that ?

The extension to this request is to use the cut command to extract the data from a particular field.

Appreciate your quick look around
# 2  
Old 02-16-2015
if you have GNU tar:

Code:
tar -xOf file.tar | grep what-you-search-for


Last edited by Scrutinizer; 02-16-2015 at 03:38 PM.. Reason: code tags
# 3  
Old 02-16-2015
Thanks. It worked.

The extension to this request to awk through the file and get all the records if a particular field value matches the search key.

Eg,

Code:
awk -F"|" '$14="<SEARCH_KEYWORD>"' <TAR_FILE>

KINDLY HELP

Last edited by Scrutinizer; 02-16-2015 at 03:39 PM..
# 4  
Old 02-16-2015
the same:

Code:
tar -xOf <TAR_FILE> | awk -F"|" '$14="<SEARCH_KEYWORD>"'


Last edited by Scrutinizer; 02-16-2015 at 03:40 PM.. Reason: Code tags
# 5  
Old 02-16-2015
Unix command to check if file name ends with .tar OR if file is a tar file

Hello Team,

Would you please help me with a UNIX command that would check if file is a tar file.
if we dont have that , can you help me with UNIX command that would check if file ends with .tar

Thanks in advance.
# 6  
Old 02-16-2015
check if file name ends with tar:

Code:
filename="blabla.tar"

if [[ "$filename" == "${filename%%.tar}" ]] ; then
  echo "is not tar"
else
  echo "is tar"
fi

check if file really a tar archive:

Code:
file filename.tar

# 7  
Old 02-16-2015
@agent.kgb:

You don't need GNU-tar, it is possible with a standard tar too by untarring to stdout:

Code:
 tar xf - /path/to/file.tar | grep "<what-you-search>"

@sanjaydubey2006:

As far as i can see agent.kgb (and the other people in the second thread you opened) have given you very sound advice. If you still are not able to do what you want to do there are two possible reasons:

Either you have not described your problem well. Instead of having asked for what you really want to do you asked for something you thought you might need to do what you want to do. Analysing a problem correctly at least to the point where one is able to concisely state what the problem is is trait you absolutely will need as a systems administrator - especially a UNIX systems administrator. Think about that.

Or - and this would pose an even greater problem - you absolutely have no idea how what you want to do is done and expect us to give you a turn-key solution. Now, i hate to break the news to you, but we cannot teach you the basics of script programming in specifc, programming in general and how a UNIX system works over the internet in a forum. This is simply not the right place for such an endeavour and i suggest you get a good book about this, take some classes or whatever means of getting tought about the topic is available for you. If this will leave specific questions you will be welcome to ask them here and get answers.

Second: we want to help, but we cannot do your work for you. We all have jobs of our own and cannot do yours. We can help you to help yourself but this is "UNIX for beginners", not "have your script written for you by willing volunteers".

There i suggest you rethink your attitude and/or the correlation of job requirements in contrast to your expertise and start over.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX command to check if file name ends with .tar OR if the file is a tar file

Hello Team, Would you please help me with a UNIX command that would check if file is a tar file. if we dont have that , can you help me with UNIX command that would check if file ends with .tar Thanks in advance. (10 Replies)
Discussion started by: sanjaydubey2006
10 Replies

2. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

3. UNIX for Advanced & Expert Users

Size of a tarball without untarring - Catch parent tar ball has sub tars

hi, I am in a weird situation. I have a parent tarball which contains 2 sub tarballs. The structure is such : Parent.tar.gz ---- > child1.tar.gz and child2.tar.gz I need to get the size of the parent tarball without untaring it I know that the command is gunzip -c parent.tar.gz | wc -c ... (1 Reply)
Discussion started by: mnanavati
1 Replies

4. Shell Programming and Scripting

How to grep the contents inside a tar file

Hi All I have searched the possibility of this options everywhere but am unable to find it in any forum. I have a tar file inside which there are n number of files and i dont know them. I need to grep a word inside the tar file and need to know in which file the word resides. > cat a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

5. Shell Programming and Scripting

untarring to the wrong dir

I am fairly new to scripting. I have a script to untar files as they come in. I keep scripts in one directory: /Scripts I get a tar'ed file in /Processing *CMD* $tar -xfv /Processing/File.tar When i run the script the untared files are placed in /Scripts i did some hunting around and... (2 Replies)
Discussion started by: purplebirky
2 Replies

6. Shell Programming and Scripting

Script Syntax on untarring file.

Trying to write a script to do the following. scp to all redhat linux host and install a antivirus tarball. Need to know what additional syntax to use to untar the file and execute the install.sh inside the tarball and then remove the tarball on all remote hosts. Here is what I have so... (2 Replies)
Discussion started by: soupbone38
2 Replies

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

8. Solaris

problem while untarring a .tarz file

Hi all, How to untar a file having .tarz extension? i tried this tar -xvfz file.tarz but i'm getting error like tar: z: unknown function modifier Usage: tar {c|r|t|u|x}] {file | -I include-file | -C directory file}... Can anyone help me out in this.... Thanks in advance.... (2 Replies)
Discussion started by: gullapalli
2 Replies

9. Shell Programming and Scripting

extract one file form .tar.gz without uncompressing .tar.gz file

hi all, kindly help me how to extract one file form .tar.gz without uncompressing .tar.gz file. thanks in advance bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

10. UNIX for Advanced & Expert Users

grep for a tar File

Hello, I made a tar with a lot of file, and i deleted all the Files. So to win tile I want to make a grep of this tar file to search any text . Is there a Unix command available for this ? I tried : grep xyz file.tar but there is nothing . Thanks for your help.... (1 Reply)
Discussion started by: steiner
1 Replies
Login or Register to Ask a Question