Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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? :)

# 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 \; > resu +lts.txt

The last one is an old Unix trick that's been around for a long time, but it still works quite well.

-- 
Education is not the filling of a pail, but the lighting of a fire.
 -- W. B. Yeats

In reply to Re: Perl and or Grep Help! by oko1
in thread Perl and or Grep Help! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found