I want to search a directory and replace all occurrences of a word in emacs [duplicate]
Possible Duplicate:
Using Emacs to recursively find and replace in text files not already open
I am using emacs and want to replac开发者_C百科e a word (well, all functions called foo() to foobar()) for all occurrences in a directory of source files. What is the best way to do this?
Burton's answer is as easy as it gets. Here's one way to do it in Emacs:
M-x dired
fill in the directory you want to work in
* s
marks all files in the directory
Q
runs query-replace-regex on all marked files. Fill in the search regex and the replace string.
Type !
to replace all occurrences in each file. You will have to go back to save the changes though.
From the shell:
sed -i 's/foo\(/foobar\(/g' *.c *.h
this will replace all instances of foo( with foobar(.
精彩评论