Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Linux
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".
Posted 4-Aug-12 20:54pm
Sandeep Mewara at 5-Aug-12 2:36am
And the issue is?

1 solution

Rate this: bad
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" {} \;
added -name which I think is necessary.
Mohibur Rashid at 5-Aug-12 10:21am
an example for grep is :
$ grep -r "redeem reward" specific_directory_path
Richard MacCutchan at 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
0 OriginalGriff 532
1 Maciej Los 450
2 Sergey Alexandrovich Kryukov 421
3 CPallini 200
4 Peter Leow 190
0 Sergey Alexandrovich Kryukov 6,888
1 OriginalGriff 5,342
2 Peter Leow 3,962
3 Mika Wendelius 2,850
4 CHill60 2,748

Advertise | Privacy | Mobile
Web02 | 2.8.150224.1 | Last Updated 5 Aug 2012
Copyright © CodeProject, 1999-2015
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