Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to write a shell script that searches the file contents in a directory and its subdirectories for a text string given by the user. It list all such file names having the given string and the store in a temp file "abc".

Regards,
Posted
Comments
Sandeep Mewara 5-Aug-12 2:36am    
And the issue is?

1 solution

Using the find[^] command combined with grep[^] should do it. It's a long time since I wrote find scripts so I cannot come up with a sample off the top of my head, but it will be something like:
JavaScript
find . -name -exec grep "pattern" {} \;


[edit]
added -name which I think is necessary.
[/edit]
 
Share this answer
 
v2
Comments
Mohibur Rashid 5-Aug-12 10:21am    
an example for grep is :
$ grep -r "redeem reward" specific_directory_path
Richard MacCutchan 5-Aug-12 12:48pm    
Not when it's part of a find command as above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900