Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

dgrep - Wrapper around gnu find & grep

by domm (Chaplain)
on Jul 22, 2002 at 20:10 UTC ( #184215=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info Thomas Klausner domm AT zsi.at
Description: I just cannot remember how to run find and grep together. After reading the FM once too often, I wrote this small wrapper..

Pass it a pseudo-regex (to match the files) and another one to look for in all files.

Example:
% dgrep .pm foo Will look for "foo" in all files ending in ".pm" in the current and lower directories.

Edited: ~Tue Jul 23 15:24:49 2002 (GMT), by footpad:
Added <code> tags to the code.

#!/usr/bin/perl -w
$|=1;
my ($findin,$grepfor)=@ARGV;
my $in=qq(find -name '*$findin' -exec grep -Hn '$grepfor' {} \\;);
print `$in`;
Replies are listed 'Best First'.
Re: dgrep - Wrapper around gnu find & grep
by jmcnamara (Monsignor) on Jul 22, 2002 at 21:08 UTC

    I usually do something like this:     find . -name \*.pm | xargs grep foo

    With egrep or grep -E as necessary. With gnu find the . isn't required. And with gnu grep you can also do the following (crude) recursive grep:     grep -rs foo *

    There are probably other ways as well.

    --
    John.

      Lest filenames with spaces, newlines or other funky bits in them trip you, you might want to get into the habit of coupling find and xargs with their respective nullbyte-termination parameters (see manpages): find . -name \*.pm -print0 | xargs -0 grep foo
      ____________
      Makeshifts last the longest.
      Ah, this

      find . -name \*.pm | xargs grep foo

      is definitly nicer than what I was using.

      Thanks.

      (But I think I'll still use my wrapper...)

      -- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://184215]
help
Chatterbox?
[stevieb]: I don't know what you mean. I write the code in C/C++ that accesses the ICs per the datasheet, wrap it for Perl, then use them. My code ensures that the functions/methods from Perl do the right thing for the chips/sensors etc
[stevieb]: At least that's what I'm working on right now. I've also been updating my automated test software Test::BrewBuild so it handles this work properly. It's not really easy meshing high level languages with low-level hardware :)
[stevieb]: this link is probably better for an overview of my test software
[stevieb]: the top-level Raspberry Pi distribution, that sucks in all sub modules. All of this software have imminent updated releases coming

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-06-25 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.