note
oko1
<p>
Right, "grep" isn't going to work despite the '-r(ecursive)' switch because you've told it to only look for *.pl files in 'mydirectory/' - and no deeper than that. It's intended to either be used with '*' as the file argument, or a list of the directories that you want to look in. You're failing with "find" because you're not asking "grep" to '-l(ist)' the files it found - and possibly because you're failing to quote the metacharacters (*). Here are a couple of ways to make these work (non-Perl... I know, how horrible, right? :)
</p>
<c>
# Search all files, then filter out the ones that don't end in '.pl'
grep -Hnr mail *|grep '^[^:]*\.pl:' > results.txt
# Find all .pl files and list the ones that contain 'mail'
find /start_dir -name '*.pl' -exec grep -l mail {} \; > results.txt
# Find all .pl files and show all the lines matching 'mail' as well as the file path
find /start_dir -name '*.pl' -exec grep -n mail {} /dev/null \; > results.txt
</c>
<p>
The last one is an old Unix trick that's been around for a long time, but it still works quite well.
</p>
<div class="pmsig"><div class="pmsig-581144">
<pre>--
Education is not the filling of a pail, but the lighting of a fire.
-- W. B. Yeats</pre>
</div></div>
882744
882744