efaq: Replacing text across multiple files
5.37 How do I perform a replace operation across more than one file?
====================================================================
Dired mode (‘M-x dired <RET>’, or ‘C-x d’) supports the command
‘dired-do-find-regexp-and-replace’ (‘Q’), which allows users to replace
regular expressions in multiple files.
You can use this command to perform search/replace operations on
multiple files by following the following steps:
• Assemble a list of files you want to operate on with either
‘find-dired’, ‘find-name-dired’ or ‘find-grep-dired’.
• Mark all files in the resulting Dired buffer using ‘t’.
• Use ‘Q’ to start a ‘query-replace-regexp’ session on the marked
files.
• To accept all replacements in each file, hit ‘!’.
Another way to do the same thing is to use the “tags” feature of
Emacs: it includes the command ‘tags-query-replace’ which performs a
query-replace across all the files mentioned in the ‘TAGS’ file.
(emacs)Identifier Search.