Question: I'm aware of `find-grep-dired`, marking the corresponding files and then pressing `Q` to run `dired-do-query-replace-regexp` on the marked files. Unfortunately that requires restarting the grep and no longer using git-grep, ack, or ag and switching to use `find-grep` which has a different syntax for searching.

I'm also aware of `multi-occur` and `occur-edit-mode`, but that requires restarting the search using occur. Finally, `ag-dired` appears to match on the filename, not on the contents of the file.

My current approach is to generate grep output, and then run a macro that starts in the grep buffer, and visits each match and changes it. I would prefer to use `query-replace` directly over the set of matches found.

What I would like to do is to either quickly build a dired buffer from existing grep output so that I can mark the appropriate files and call query-regexp on them, or transform grep output into a list of buffers for `multi-occur` so that I can use `occur-edit-mode` to edit it in place and run `query-replace` on that buffer.

Does this functionality exist, or is there another workflow that solves this problem?

Answer: 
> 
> What I would like to do is to either quickly build a dired buffer from existing grep output [...], or transform grep output into a list of buffers for multi-occur [...].
> 
> 
> 

You don't need to convert the grep results buffer into anything, there's already a mode specifically for editing grep output (and reflecting the changes on the files, of course).

1. Install the [wgrep](https://github.com/mhayashi1120/Emacs-wgrep) package from Melpa.
2. `(require 'wgrep)` in your init file.
3. After doing a grep search, hit `C-c C-p` and edit away!
4. Save your edits with `C-c C-e`

It even works with ack and ag as well.
I use this util I wrote
[xah\_find.el](https://github.com/xahlee/xah-find)

I wrote it because:

* Pure elisp. No more worry about grep on Windows or Unicode transmission between emacs to Operating System. [emacs grep problem](http://ergoemacs.org/emacs/emacs_grep_problem.html)
* If you are heavy unicode user, the unix tools has some semi-bugs. [linux uniq problem](http://xahlee.info/comp/unix_uniq_unicode_bug.html)
* I do find/replace every week on 5k files. I was using dired-do-query-replace-regexp for years. I find the interactive nature really zapped my time, yet I do need to check results of the changes. So, my solution is now run batch but have a nice report that I can scan at all find/replace results, with option to write to file.

This elisp util is perhaps 5 to 10 times slower than calling unix grep in emacs, but worked ok for me.