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 Zoltán Zörgő 330
1 Sergey Alexandrovich Kryukov 230
2 Peter Leow 204
3 OriginalGriff 160
4 88388132 128
0 Sergey Alexandrovich Kryukov 8,288
1 OriginalGriff 6,396
2 Peter Leow 3,557
3 Zoltán Zörgő 3,221
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web01 | 2.8.150123.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