Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Grep string in files and list file names that contain the string

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 18 June 2015, 4:02 AM EDT
Posts: 61
Thanks: 33
Thanked 1 Time in 1 Post
Grep string in files and list file names that contain the string

Hi,
I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat.
My OS is:
SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise
Sponsored Links
    #2  
Old Unix and Linux 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 1 September 2015, 1:18 PM EDT
Location: Chennai
Posts: 573
Thanks: 50
Thanked 75 Times in 73 Posts
Do your system has zgrep ??
Sponsored Links
    #3  
Old Unix and Linux 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 18 June 2015, 4:02 AM EDT
Posts: 61
Thanks: 33
Thanked 1 Time in 1 Post
no, don't have zgrep.
    #4  
Old Unix and Linux 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 1 September 2015, 1:18 PM EDT
Location: Chennai
Posts: 573
Thanks: 50
Thanked 75 Times in 73 Posts
Without that you could use

zcat (in case of .Z files)
Sponsored Links
    #5  
Old Unix and Linux 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 18 June 2015, 4:02 AM EDT
Posts: 61
Thanks: 33
Thanked 1 Time in 1 Post
Quote:
Originally Posted by PikK45 View Post
Without that you could use

zcat (in case of .Z files)
Hmmm, not really sure how to use that?
Sponsored Links
    #6  
Old Unix and Linux 03-26-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 3 September 2015, 1:40 PM EDT
Location: Saskatchewan
Posts: 20,928
Thanks: 917
Thanked 3,738 Times in 3,490 Posts
Kind of the same way you'd use cat...

If you don't have gzcat it's simple enough to make one:


Code:
for FILE in *.gz ; do gunzip < $FILE ; done | ...

Sponsored Links
    #7  
Old Unix and Linux 03-27-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 18 June 2015, 4:02 AM EDT
Posts: 61
Thanks: 33
Thanked 1 Time in 1 Post
gzcat is OK

Code:
gzcat *.gz|grep string

But that do not give me the file names in which the string is found.
I also tried:

Code:
gzcat *.gz|grep -l string

But that doesn't work, it gives me an error.
So my question is, is there any way to get the file names using gzcat?

Thanks!
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep exact string from files and write to filename when string present in file JC_1 Shell Programming and Scripting 4 08-06-2012 10:52 PM
Grep a string from input file and delete next three lines including the line contains string in xml greet_sed Shell Programming and Scripting 4 09-28-2011 05:18 AM
How to grep the specific string or user's list from the file rohit22hamirpur Programming 1 07-25-2011 12:11 AM
problem with grep on search string in a txt file over multiple files m00 UNIX for Dummies Questions & Answers 2 05-18-2008 02:21 PM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 03:17 AM



All times are GMT -4. The time now is 03:11 PM.