[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: GREP



  the difference is that when you use -exec grep is called once for each
file, with xargs it is called with all the files (you can add parameters
to xargs to change it).

  calling grep just once is probably slightly more effective (even
though the grep stays in cache so it's not that much of a difference, I
guess)

  the main difference is a sideeffect, sort of, if grep is called for
with one file as an argument it only prints the line matched, not the
filename, so you get bunch of lines (each successfull match) but you
have no idea which files these lines are in...

  of course, you can use -print -exec ... but that prints all the files
found and lines matched in between (plus I am not sure if the order is
guaranteed, even though it works as far as I can tell from experience)

  I can also use:

  grep '[sf]printf' `find / -name '*.h' -print`

  and probably some other more or less dirty tricks...

	erik

Damian Menscher wrote:
> 
> On Fri, 20 Oct 2000, Erik Steffl wrote:
> 
> >   yes, that's true, are you asking what the '?' is or are you just
> > stating the fact? anyway, the other command is find, see manpages for
> > find and grep for more info. find is the one that finds file (based on
> > name, time last accessed, type and various other criteria), grep
> > searches the files for string (regular expression). xargs is often
> > useful in commands like this:
> >
> >   find / -name '*.h' -print | xargs grep '[sf]printf'
> 
> Just curious, but is this any better/worse than doing a
> 
> find / -name '*.h' -exec grep '[sf]printf' {} \;
> 
> My way seems more straightforward, but I'm not sure about differences in
> processing time, when the first match would be found, etc.
> 
> Damian Menscher
> --
> --==## Grad. student & Sys. Admin. @ U. Illinois at Urbana-Champaign ##==--
> --==## <menscher@uiuc.edu> www.uiuc.edu/~menscher/ Ofc:(217)333-0038 ##==--
> --==## Physics Dept, 1110 W Green, Urbana IL 61801 Fax:(217)333-9819 ##==--
> 
> --
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null



Reply to: