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

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

Cool M-x grep trick: was: Re: grep command adds "NUL"


From: David Combs
Subject: Cool M-x grep trick: was: Re: grep command adds "NUL"
Date: Wed, 1 Jan 2003 01:18:50 +0000 (UTC)

In article <mailman.1038896044.20756.help-gnu-emacs@gnu.org>,
Eli Zaretskii  <eliz@is.elta.co.il> wrote:
>
>On Tue, 3 Dec 2002, Leo wrote:
>
>>         cd C:/mydir/
>>         grep -n 'spider' *.pas NUL
>>         spidermain.pas:368:     115  spider:= TSpider.Create;
>>         grep: NUL: Permission denied
>> 
>>         grep exited abnormally with code 2 at Tue Dec 03 15:59:34
>> 
>> looking in the elisp source tells me, that emacs wants to add a null-device.
>> why that?
>
>It does so because ``normal'' (read: Posix-compliant) versions of Grep 
>don't report file names when you run them on a single file.  Adding the 
>system null device makes the list of files be always at least 2 files 
>long, so file names are reported.  (Emacs needs the file names to let you 
>jump to each match found by Grep.)
>
>Since you run Emacs on Windows, I'm guessing that your Grep is not 
>Posix-compliant, perhaps from Borland?  In that case, I suggest you find 
>a port of GNU Grep and install it; then the problems will go away.

Net trick:

When you do M-x grep, you see this prompt to you:

     Run grep (like this): grep -n

, with which you edit that "grep -n" to be whatever
kind of grep, etc, you want.

Suppose, however, you want to do some more complex
filtering than possible with just one grep -- 
perhaps a grep pat files... | grep -v not-pat | someFilter.pl (perl) |
  sed ... | and then run through some program that
does *not* use standard-input or -output, ... --

supposse *that's* what you want as your "found-by-grep"-type
set of lines.

TRICK: do the grep -n on the files, if only to get
the line-numbers added on the left.  Then do
whatever you have to do to get the pretended-grep-output
lines into a file, eg foo.out.

THEN, do M-x grep, and instead simply appending to
the prompt-suggested "grep -n", *change* the
whole thing to "cat foo.out".

Works dandy!

----

You can even *modify* those "grepped out" lines,
because the *only* thing that matters (for
jumping via C-c C-c from *Occur* into the
original line at that line-number, is the
*line-number* (or "fileName:lineNumber:hacked-line").

This trick can sure speed up doing massive edits
on eg a book.

David


reply via email to

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