We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

15

Well, since the original question doesn't mention rgrep, I'll go ahead and point it out here. This is the simplest option already built into Emacs, and I've found it to be more than sufficient for most things. From the documentation, Recursively grep for REGEXP in FILES in directory tree rooted at DIR. The search is limited to file names matching shell ...


11

I happily use M-x find-grep-dired for years. It returns the results as a dired buffer, which you could use.


10

Absolutely. And it is extremely useful to do that. M-x flush-lines and M-x keep-lines are your friends, as well as just C-k etc. (The first thing you need to do is of course C-x C-q, to make the buffer writable.) If you use library Grep+ (grep+.el) then you have these commands, which remove comment lines and toggle such removal: grepp-remove-comments, ...


9

You have two ways: Use helm-projectile-grep/ack/ag: You can search for everything starting from project root. Later if you want to save the search results, press F3 or press TAB to switch to action menu and select the 3rd action. To navigate hgrep buffer: C-<down>: go to next match and open the match. C-<up>: go to previous match and open the ...


7

Emacs provide lgrep and rgrep as convenient interfaces for grep. These commands may invoke grep on the command line with grep options systematically (see also the GNU Emacs Reference Manual). More specifically, the user option grep-find-ignored-files (discovered after searching in the source code and in the integrated documentation) may be set to ignore some ...


6

If you use library Dired+ (dired+.el) then you can use command dired-do-grep (bound by default to M-g in Dired mode) to do what you request. diredp-do-grep is an interactive compiled Lisp function in dired+.el. (diredp-do-grep COMMAND-ARGS) Run grep on marked (or next prefix arg) files. A prefix argument behaves according to the ARG ...


5

I'm awfully confused if you didn't actually try C-o, because by default that same binding does exactly what you want in grep buffers as well as in occur buffers. You can also simply navigate up and down inside the grep results buffer with p and n (previous-error-no-select, next-error-no-select), and the other buffer will be updated each time. Outside of ...


5

Preferred solution I have settled with using "ag" (The Silver Searcher) for search and "helm-ag" or "ag.el" for Emacs integration. "ag" allows you to specify a ".agignore" file where you can add file/directory patterns that will be ignored for the search - exactly what I was looking for. For example: # .agignore folder file.txt *.js It also takes "....


5

Solution 1 (best solution): Install counsel (https://github.com/abo-abo/swiper/blob/master/counsel.el) Then M-x counsel-git-grep. No setup needed (git knows the project root and files to exclude). Both git grep and counsel is efficient. The project need be managed by git. counsel requires ivy-mode. Solution 2: This solution uses grep and works on any ...


5

Try using the UNIX or GNU/Linux find command. It supports Boolean operations. In Emacs you can, for example, use command find-dired, which runs find and puts the set of found files in a Dired buffer. You can then mark any number of them and then act on the marked files (e.g. A to search incrementally, Q to query-replace). (Emacs also has a grep-find ...


5

A recursive grep in a directory should be the simplest thing For a simple recursive grep inside current directory, just: M-x grep then, inside the minibuffer: Run grep (like this): grep -nHr "pattern". (notice the -r flag). You may also be interested by rgrep: rgrep is an interactive autoloaded compiled Lisp function in `grep.el'. (rgrep REGEXP &...


5

Note that the first grep grep --color=always -nH -e "text_to_find" ~/path/to/files/*.org puts escape sequences around matches for text_to_find to colorize those matches. If the second search string text_to_ignore contains text_to_find. Matches of text_to_ignore in the original files are not found in the output of the first grep call because of those escape ...


4

I'd like to add another solution to @chen bin's solution which also uses counsel (but you don't need to have a project maintained by git for this). You need to install ag (the silver searcher) and counsel provides the command counsel-ag which searches the current directory for the entered string. If you want to search within a project(not just the ...


4

(defun dired-grep-marked-files () "`i` case insensitive; `n` print line number; `I` ignore binary files; `E` extended regular expressions." (interactive) (let* ((files (dired-get-marked-files)) (search-term (read-string "regex: ")) (grep-command (concat grep-program " " "-inIE --color=...


4

I found the answer to my own question. It seems M-x grep is pretty powerful, in that it can handle any "grep like" shell command's output. So you can do M-x grep # it will ask you for the command, paste this git --no-pager grep -n -e 'include' --and -e Image and voila!


4

The grep parameters you are using should be adequate. Just do M-x grep-mode after opening your results file and you should get the links you desire. You could also skip writing the grep results to a file and use a command like grep-find directly. In grep mode, n/p are bound to next-error-no-select/previous-error-no-select respectively (open the file and ...


4

What you were attempting with a pipe works fine for me (tested in 26.1 and 25.3). Which version are you using? Does your command work outside of Emacs? Edit: C-hv grep-use-null-device might mess up your command, by preventing the second grep from reading stdin. This would be apparent in the command line displayed in the grep buffer. If this is the issue, ...


3

find-dired will run find for you.


3

M-x rename-buffer. Use M-n to retrieve the current name, and edit it. E.g., M-n puts *grep*in the minibuffer. Type 1 to change it to *grep*1, etc. Then just use M-x grep again, to have the new search output go to the (new) buffer *grep*. (I bind rename-buffer to C-M-S-<f1>.) As @JeanPierre pointed out in a comment, you will need to first make ...


3

Eshell's grep is compatible with grep(1) and uses Emacs's internal grep interface, thus you can try something like the following: M-x dired-do-eshell-command RET grep -nH --color your-search--pattern RET (defun dired-do-eshell-command (command) "Run an Eshell command on the marked files." (interactive "sEshell command: ") (let ((files (dired-get-...


3

The following solution relies upon three (3) command-line utilities: find; xargs; and zgrep. In putting together the following function, I discovered that grep cannot see inside gizipped files, and not all versions of zgrep are able to search recursively. Inasmuch as zgrep can handle both gzipped and unzipped .info files, the function includes a search ...


3

Here is the complete solution: (setcar (car grep-regexp-alist) "^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)[ \t]*\\2") (defun eab/grep-align () (interactive) (read-only-mode -1) (toggle-truncate-lines 1) (save-excursion (beginning-of-buffer) (compilation-next-error 1) (call-interactively 'set-mark-command) (end-of-buffer) (...


3

You need to use cygwin's or msys find command. The error messages shown above seem to come from the windows find command that is incompatible with emacs. See "Using grep' andfind' on MS Windows" on emacswiki.org


3

grep (rgrep) uses two settings (that I know of) to control highlighting in the *grep* buffer font-lock-mode grep-highlight-matches - customization variable grep-highlight-matches depends on font-lock-mode being on. It can inherit its value from grep-host-defaults-alist. It controls the use of the GREP_COLORS environment variable and grep --color argument. ...


2

As correctly guessed by Tyler, what's happening is that ps is truncating the output to the width of the terminal when it's running in Emacs Term, but not when it's running elsewhere. You can see that in the line where you grep for 13109. Note that it's ps doing the truncation, not the terminal. The reason this happens is that Term sets the COLUMNS ...


2

I think the Emacs shell is telling ps what the column width is, and that causes ps to truncate its output. You can explicitly set the output width to unlimited by setting the -w argument twice: ps -ef -w -w. This overrides whatever settings Emacs is setting in shell mode.


2

In addition to the tools mentioned in the other answers, another cool function is find-grep-dired which creates a dired buffer containing all files matching a recursive grep pattern. It just runs find . \( -type f -exec grep -q -e my-regular-expression \{\} \; \) -ls and displays the results in a dired buffer.


2

Here is an example of a custom grep function that recursively greps file contents (using a regexp for the search term) in a directory and its subdirectories, and displays the results with lines of context before and after. The built-in compile.el and grep.el libraries provide for several methods to jump to the location in the file containing the search ...


2

This is an emacs bug in emacs 26.1, resolved in 26.2. It has to do with —null being added to the default grep arguments, so the drive letter in Windows paths, with its colon, was not matched by the grep regexp. You can either upgrade to the unreleased version, or customize the grep arguments to remove —null.


2

The cause of that error is a fixed problem in Projectile. Avoid this problem by updating to a Projectile version where this problem is fixed.


Only top voted, non community-wiki answers of a minimum length are eligible