> *Yes, what I'm looking for is (something close to) a command that iterates over matched files in the grep buffer and calls query-replace for each.*

OK, I just added command `diredp-compilation-files-other-window` to [**Dired+**](http://www.emacswiki.org/emacs/DiredPlus), which can help with this.

You use it in a compilation buffer (any buffer, such as `*grep*`, that is in a mode derived from `compilation-mode').

It prompts you for the name of a new Dired buffer, and it opens Dired on all of the files corresponding to the compilation hits, regardless of what directories they are in.  IOW, the files can be in different directories.

In that Dired buffer, you can then:

1. Use `t` to mark all of the files.
2. Use `Q` to query-replace across all of the files.

(`Q` is standard Dired command `dired-do-query-replace-regexp`).

Instead of `Q` you can use `A` to  search the files, `D` to delete them, `P` to print, `Z` to compress, `!` to run a shell command, etc.