LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-07-2007, 01:17 AM   #1
prernabhagat
LQ Newbie
 
Registered: Oct 2007
Location: Mumbai
Posts: 5

Rep: Reputation: 0
grep a word in a .tar.gz file


Can anyone tell me how to search a word in files which have been zipped in a tar file using the tar -zcvf command.............
 
Old 12-07-2007, 01:53 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
It depends exactly what you want to do.

If you just want to test for the presence of a pattern, you can use zgrep. If the pattern exists in any of the files which are in the tar file it should see it. However, you won't get any idea about which file in the archive the pattern was found in. It will also find the pattern if it is part of tar's archive structure, which might not be what you want.

If you need more information, or to avoid possible false positives with matches in the tar structure, you need to extract the archive to some temporary area and then grep it.

A quick google reveals a Perl module for handling tar files. If your file fits easily in memory you might have joy writing a simple program to do that rather than extract it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word count with grep DiagonalArg Linux - Software 3 02-13-2006 12:46 PM
grep data between two word DropSig Linux - General 2 01-27-2006 08:31 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
grep to NOT select a word robertmarkbram Programming 2 08-21-2003 10:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration