help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: using find-grep in emacs


From: Andreas Röhler
Subject: Re: using find-grep in emacs
Date: Tue, 14 May 2013 19:19:17 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5

Am 14.05.2013 17:42, schrieb Bob Proulx:
Peter Dyballa wrote:
schrieb Andreas Röhler:
Because a Null -- 0 -- offers the most space to fill all that in?

No! It's the least space to read from. No other file ends earlier.

In case this issue confuses people I wanted to say a few words.  Prior
to the addition of the grep -H option the behavior was this following.
The grep, egrep, fgrep programs would print matching lines from files.
If one file was searched then no file name would be printed.  If more
than one file was searched then grep would prefix the line by the name
of the file so that you could tell which file it came from.

So the problem was how do you instruct grep to print the name of the
file even when you were only searching one file?  The answer was to
tell grep to search more than one file.  But, you say, I only want to
search one file.  The answer is to search /dev/null in addition to
whatever file you are wanting to search.  /dev/null will return end of
file immediately.  It won't use any cpu time.  With multiple files
being searched grep will print the file name on each line.  An elegant
Unix solution.  That is why the grep template uses grep with /dev/null
so that grep will print the file name so that Emacs compile mode can
parse it.

GNU grep has an extension to print file names without needing to have
an extra null file argument.  With GNU grep you can specify the -H
option and GNU grep will print the file name for all matches
regardless of the number of files being searched.  Newer emacs
versions use this option and make the assumption that you have GNU
grep available.  (Or it might figure it out dynamically.  I don't
know.)

But the grep -H option is only available in GNU grep for the GNU
system and BSD grep for BSD systems.  It is not available in the older
traditional Unix systems.  It isn't in the POSIX standard.  Therefore
using -H is non-portable.  It won't work on HP-UX or IBM AIX for example.

   http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html

But if you are using Emacs then you probably have grep -H available
too and might as well use it.

The Emacs grep find templates can be customized.  See the
grep-find-template variable in this case for example.

Bob



Thanks a lot digging into, great to learn that.

Andreas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]