The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
How to search and replace text in same file Vrgurav Shell Programming and Scripting 1 04-25-2008 06:20 AM
Search first line of compressed file cbreiner UNIX for Advanced & Expert Users 1 09-05-2007 05:52 PM
Search file contain some text yuimyt UNIX for Dummies Questions & Answers 5 05-22-2006 04:31 PM
Search for repeats in text file - how? aarondesk UNIX for Dummies Questions & Answers 4 04-03-2006 04:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-26-2005
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question How to search for text within compressed file

I was wondering if there's a way to search within a file that's been compressed. i.e. if file a is inside file a.zip or a.gz, is there a a command that will retrieve the string of data I'm looking for in file a, and list which compressed file it found it in?

Please help!

Thanks.

Last edited by HLee1981; 07-26-2005 at 03:46 PM..
  #2 (permalink)  
Old 07-26-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
man gunzip
man grep

gunzip -c file.gz | grep pattern

Last edited by vgersh99; 07-26-2005 at 02:53 PM..
  #3 (permalink)  
Old 07-26-2005
fdarkangel's Avatar
fdarkangel fdarkangel is offline
Registered User
  
 

Join Date: Apr 2005
Location: /dev/null
Posts: 42
or...
zcat file.gz | grep foo
  #4 (permalink)  
Old 07-27-2005
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question

1) What if I do not know which file contains the string of text I am looking for?

2) Will this work for only .gz files, or for other compressed files as well, i.e. .zip, etc.?

Thanks!
  #5 (permalink)  
Old 07-27-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by HLee1981
1) What if I do not know which file contains the string of text I am looking for?
That's what grep does best. Given some files to grep, it searches for the pattern in those files. So you need not worry about that. It will throw up all searches which are successful. i.e. files which contain the pattern.

vino
  #6 (permalink)  
Old 07-27-2005
infierno's Avatar
infierno infierno is offline
Registered User
  
 

Join Date: Jul 2005
Location: Asuncion, Paraguay
Posts: 79
Quote:
Originally Posted by fdarkangel
or...
zcat file.gz | grep foo
this can lead to Binary file (standard input) matches,...

to display strings type

zcat file.gz | strings | grep foo

best regards!
  #7 (permalink)  
Old 07-28-2005
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
If you have an upto date versoin of gzip installed you probably have zgrep as well which will do the lot for you.

zgrep foo <compressed file list>
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0