[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgi-list
Subject:    RE: [CGI] OFF TOPIC: unix question grepping all files in a dir structure for specific words
From:       Bill Mills-Curran <bcurran () clariion ! com>
Date:       1998-07-27 12:35:21
[Download RAW message or body]

Efficiency note:

Piping the output of find to an "xargs" command is MUCH more efficient
than using the "-exec" option in find.  The reason is that "find
-exec" will fork/exec a subprocess for each match.  In contrast, xargs
runs as few commands (subprocesses) as possible by packaging up a
large argument list.

Bill

On Sat, 25 Jul 1998, Jann Linder wrote:

> SOLUTION:  a menage of several answers:
> 
>  find ~/www/htdocs/Perl -type f | xargs grep -c '\.pl'
> 
> gave me what i needed.
> 
> it lists the files and the count in each file from the current dir DOWN.
> 
> 
> 
> Jann Linder
> Web Developer/CH2M Hill - SFO
> jann@jann.com
> Home Page:
>      http://www.jann.com/
> CalendarPlus Web Site:
>      http://www.calendarplus.com/
> #include <std/disclaimer.h>
> 
> 
> 
> -----Original Message-----
> From: Jonathan Peterson [mailto:jon@amxstudios.com]
> Sent: Saturday, July 25, 1998 9:38 AM
> To: Jann Linder
> Subject: Re: [CGI] OFF TOPIC: unix question grepping all files in a dir
> structure for specific words
> 
> 
> At 08:40 AM 7/25/98 -0700, you wrote:
> 
> >How do you funnel filenames into grep for searching file contents.
> >I thought it was this:
> >find ~/www/htdocs/Perl | grep -e .pl {};
> >I wish to find all files in the ~/www/htdocs/Perl dir that contain the word
> >'.pl'
> 
> 
> If everything is in one dir it is easy:
> 
> grep '.pl' *
> 
> If you want to be recursive, then yes you need find. I tend to use the
> might xargs (even tho it is not necessary) because it is easier to remember:
> 
> find ~/www/htdocs/Perl -type f |xargs grep '\.pl'
> 
> the -type f means 'only find files' (rather than dirs...)
> 
> your version of grep may well be different. You may or may not need to
> escape the . in the expression.
> 
> --------
> Jon Peterson  AMXstudios Ltd  London, UK  +44 171 613 5300
> 
> An apple a day makes 365 apples a year.
> 
> 
> 
> -----------------------------------------------------------------
> For subscription information, http://www.jann.com/
> 
> The CGI Tips & Tricks website (and archive of the list) is located
> at http://www.jann.com/Perl/
> 
> cgi-list is hosted by Summit Communication Design (http://www.summitdesign.net).
> -----------------------------------------------------------------
> 
> 

-----------------------------------------------------------------
For subscription information, http://www.jann.com/

The CGI Tips & Tricks website (and archive of the list) is located
at http://www.jann.com/Perl/

cgi-list is hosted by Summit Communication Design (http://www.summitdesign.net).
-----------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic