Click here to Skip to main content
12,503,591 members (44,896 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Linux
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 4-Aug-12 19:54pm
Comments
Sandeep Mewara 5-Aug-12 2:36am
   
And the issue is?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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:
find . -name -exec grep "pattern" {} \;

[edit]
added -name which I think is necessary.
[/edit]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 5 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100