Grep string in files and list file names that contain the string | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 17 July 2014, 5:56 AM EDT
Posts: 59
Thanks: 31
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 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 10 July 2014, 12:57 PM EDT
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 Posts
Do your system has zgrep ??
Sponsored Links
    #3  
Old 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 17 July 2014, 5:56 AM EDT
Posts: 59
Thanks: 31
Thanked 1 Time in 1 Post
no, don't have zgrep.
    #4  
Old 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 10 July 2014, 12:57 PM EDT
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 Posts
Without that you could use

zcat (in case of .Z files)
Sponsored Links
    #5  
Old 03-26-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 17 July 2014, 5:56 AM EDT
Posts: 59
Thanks: 31
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 03-26-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 27 August 2014, 11:08 PM EDT
Location: Saskatchewan
Posts: 19,269
Thanks: 774
Thanked 3,235 Times in 3,033 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 03-27-2013
apenkov apenkov is offline
Registered User
 
Join Date: May 2009
Last Activity: 17 July 2014, 5:56 AM EDT
Posts: 59
Thanks: 31
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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:05 AM.