Operating System - HP-UX
1758532 Members
2108 Online
108872 Solutions
New Discussion юеВ

how to search strings in multiple files recursively

 
SOLVED
Go to solution
Wang,MinJie
Super Advisor

how to search strings in multiple files recursively

Hi all
I'm not good at shell programming
I know that if you want to search one string within a directory ,you can run "grep *" to complete.
But if there is a sub directory and you also want to search,how can you do this job recursively.
What if there is another sub directory in that sub directory?
Tks in advance
3 REPLIES 3
Torsten.
Acclaimed Contributor
Solution

Re: how to search strings in multiple files recursively

Many ways to achieve this.

One is mentioned in the find man page:

Search the two directories /example and /new/example for files containing the string Where are you and print the names of the files:

find /example /new/example -exec grep -l 'Where are you' {} \;


http://docs.hp.com/en/B2355-60103/find.1.html

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Dennis Handly
Acclaimed Contributor

Re: how to search strings in multiple files recursively

>Torsten: One is mentioned in the find man page:

For performance a "+" should be used instead:
find /example -exec grep -l 'Where are you' {} +
Wang,MinJie
Super Advisor

Re: how to search strings in multiple files recursively

Thank you guys
It absolutely helped!