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

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

Re: find string in files


From: David Combs
Subject: Re: find string in files
Date: Sun, 19 Nov 2006 22:55:46 +0000 (UTC)

In article <address@hidden>,
Pascal Bourguignon  <address@hidden> wrote:
>Gary Wessle <address@hidden> writes:
>
>> how can I have the output of "$ grep -FHwire string path" in a window
>> in the same frame with each line hyperlinked so that by placing the
>> pointer and <RET> it takes me there?
>
>M-x grep RET (edit the command) grep -FHwire string path RET
>
>
>> this command is just a shell command to find exact string recursively
>> in a given path.
>
>You'll probably want to keep -n


(Absolutely keep -n  --  that's what emacs uses to go-to
  that line!)


Here's what I do:

In *shell*:

  egrep -in mypattern set-of-files-to-look-in > t.loc
   (note: you MUST either list TWO-or-more files (so as
    to get the file-names in the t.loc lines),
   or accomplish the same via the gnu-egrep option that forces that.

Then, do M-x grep

   and CHANGE the offered grep-stmt to "cat t.loc"

   and THEN hit <return>.

My reason for doing it in these two steps:

.  Enables me to mess around, make mistakes, retry, etc,
    the egrep (OR WHATEVER!) to create that t.loc output-file.

.  The "or whatever!":  all emacs cares is that t.loc 
    LOOKS LIKE the result of a grep -n --
    ie, has lines of the form:

     relative-or-absolute-path-name COLON lineNum COLON 
(optionally!)the-text-at-that-lineNum

.  about that "(optionally!)the-text..." -- emacs (it seems to me) totally
   *ignores* that text, relying solely on the target line-number.

   THUS -- you can do what ever you want to that egrep-found text --
    such as when running through some text someone has written,
    and you want to make sure that the word "which" wasn't used
    where a "that" would have been better,

  you can modify your t.loc from, say, 

 foo.txt:100:Now is the time for a good man, which is sorely needed in 
 foo.txt:123:that is the location which I saw yesterday when
 foo.txt:147:and she was the date which he went to the
 ...
    
 foo.txt:100:Now is the time for a good man, **WHICH** is sorely needed in 
 foo.txt:123:**THAT** is the location **WHICH** I saw yesterday when
 foo.txt:147:and she was the date **WHICH** he went to the
 ...
 
, enabling you to easily spot all uses of that and which in *grep* --
yet when you ^C^C on a *grep* line, the corresponding one it goes
to, in the actual target file, has *not* been modified.

Nifty.


Also, I believe I had success when using the egrep options -A and -B,
to get surrounding context.


And, you can write your own program or script to hunt down interesting
places in files -- just so your output t.loc file *appears to emacs*
to be output from grep -n.

I hope these hints aid others -- they sure have helped me! 

David

   


reply via email to

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