Operating System - HP-UX
1832009 Members
2893 Online
110034 Solutions
New Discussion

Re: String search in a set of files!!!

 
SOLVED
Go to solution
Deepu Chakravarty
Regular Advisor

String search in a set of files!!!

If I have few files and want to search a partcular word/string in those files, what should be the actual command? So that a single command can give all occurrances of that word in those files.
4 REPLIES 4
Vibhor Kumar Agarwal
Esteemed Contributor
Solution

Re: String search in a set of files!!!

find . -name "your_wild_card" -type f -exec grep -l "search_string" {} \;
Vibhor Kumar Agarwal
Vibhor Kumar Agarwal
Esteemed Contributor

Re: String search in a set of files!!!

Clicked the submit button bit quickly.

The "-l" option will give you the filename.

You can also use the for loop.

for filename in `find . -type f -name "pattern"`; do grep -l "search_string" $filename; ... done;
Vibhor Kumar Agarwal
Eknath
Trusted Contributor

Re: String search in a set of files!!!

HI Deepu,

If you want to search in all files in current directory (All files need to be text)
just say #grep "Your Text" *

Cheers!!!
eknath

Deepu Chakravarty
Regular Advisor

Re: String search in a set of files!!!

thanks to all who participated in this thread.