sudo
sudo

Reputation: 647

emacs find-grep grep

I try to do a grep on the result of emacs' find-grep, so I use the following command:

find ... | xargs ... | grep -v "include"

The result does show up i the grep buffer, but when I press enter on each entry trying to go to that file, emacs says that file does not exist. On the minibuffer, before the full path of the file, there is a ^[[K character. That basically make the the whole file name unrecognizable. I looked through grep's manual, still no sure what I can do about it.

I probably don't have to do this, but I'm just not sure how to pass two pattern, one is for grep and the other one is to inverse grep. (May be regular expression?)

Anyone has any suggestions on this?

Solution:

I was doing this on a Cento 5.5 machine. It turns out to be a issue due to the old version of grep. I installed a latest version of grep in my home directory, and everything's good now.

Upvotes: 4

Views: 1636

Answers (2)

Mitten.O
Mitten.O

Reputation: 745

I had the same problem, but couldn't change my version of grep, so I used a workaround. The problem seemed to be greps line endings so I simply run the results of grep through awk and print them as is.

... | grep -v blaa | awk '{print $0}'

This fixes the problem for me, though I don't know why.

Upvotes: 0

Trey Jackson
Trey Jackson

Reputation: 74430

After "debugging" the issue through the comments, this is a solution that should work for you. Add it to your .emacs and customize it so that the regexp matches the special characters you want to strip from the filename: ^[[K

(defadvice compilation-find-file (before compilation-find-file-strip-odd-chars activate)
  "Strip the ^[[K in the input string"
  (let ((filename (ad-get-arg 1)))
    (save-match-data
      (when (string-match "^\\[\\[K" filename)
        (ad-set-arg 1 (replace-match "" nil nil filename))))))

Upvotes: 3

Related Questions