Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl and or Grep Help!

by oko1 (Deacon)
on Jan 17, 2011 at 23:45 UTC ( #882777=note: print w/replies, xml ) Need Help??


in reply to Perl and or Grep 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

Replies are listed 'Best First'.
Re^2: Perl and or Grep Help!
by Anonymous Monk on Jan 18, 2011 at 14:56 UTC
    Thanks, it worked very well. I could also specify on this one as an example exclusion of directories I don't want it to scan right?
    find /start_dir -name '*.pl' -exec grep -n mail {} /dev/null \; > res +u +lts.txt
Re^2: Perl and or Grep Help!
by Anonymous Monk on Jan 18, 2011 at 15:50 UTC
    find /start_dir -name '*.pl' -exec grep -n mail {} /dev/null \; > results.txt

    What is the purpose of the /dev/null? I seem to get the exact same results with and without it.

Re^2: Perl and or Grep Help!
by Anonymous Monk on Jan 18, 2011 at 15:19 UTC
    I am trying this way, no success yet.
    find apps/ac/ -name '*.pl' -type d \( -name dirto_escape -o \) -prune +-o -print -exec grep -n sendmail {} /dev/null \; > apps/ac/grep/resu +lts.txt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://882777]
help
Chatterbox?
[LanX]: ... so my boss started a project with the newest sun servers and invited the traders to come on weekend to test it... and they were so pleased, that they forced him to keep it in production...
[ambrus]: Corion: sure, this is the long-term plan. The short term is that I have to run this ungodly mess to get results from the new input data today.
[Corion]: ambrus: Most of our "automation" is tied to process exit codes and a shell pipeline :-\
[LanX]: ... a week later they realized that one of the databases - which recorded how much the other banks due to this bank - was not correctly plugged
[ambrus]: Corion: I have no problem with exit codes and shell pipeline. My problem is that the current process requires a lot of manual intervention from me, including editing the source codes.
[ambrus]: (Also a lot of manual intervention by two or three other co-workers, who do other parts of the process.)
[ambrus]: Some of the manual part is unavoidable, but not all.
[choroba]: LanX was there a way to recover the numbers from the remaining information?
[Corion]: LanX: Ow ;)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2017-03-29 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.