How to Write grep in Emacs Lisp (tutorial)

Rob Warnock rpw3 at rpw3.org
Thu Feb 10 04:39:08 CET 2011


Harald Hanche-Olsen  <hanche at math.ntnu.no> wrote:
+---------------
| [Icarus Sparry <i.sparry+un at gmail.com>]
| > The 'modern' way to do this is
| > find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
| 
| Actually, I think it should be
|   find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} +
| because grep behaves differently when given only one filename as opposed
| to several.
+---------------

Yup. This is why it's also important to include that "/dev/null"
when using "find | xargs", too:

    find . -maxdepth 2 -name '*.html' -print | xargs grep whatever /dev/null

Years & years ago, right after I learned about "xargs", I got burned
several times on "find | xargs grep pat" when the file list was long
enough that "xargs" fired up more than one "grep"... and the last
invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T
TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!!  :-{

The trailing "/dev/null" fixes that.  ;-}


-Rob

-----
Rob Warnock			<rpw3 at rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607




More information about the Python-list mailing list