2009-06-03 77 views
1

可能重複:
Using Emacs to recursively find and replace in text files not already open如何在emacs中進行大量的搜索和替換?

重複:using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open

我需要向正則表達式搜索和文件的列表上取代。 是否有一個emacs命令(命令組合)? 或者,也許你有一個更好的方式來在Linux上做C++重構?

+1

看使用Emacs以遞歸查找和替換文本文件尚未打開(http://stackoverflow.com/questions/270930/:不然爲什麼不能與某些findsed魔法,一拉使用shell使用-emacs的對遞歸查找和替換功能於文本文件 - 不已經打開)。 – 2009-06-03 11:07:40

+1

有沒有一個原因,爲什麼這需要在emacs而不是其他工具,如sed? – 2009-06-03 11:33:29

+2

因爲在emacs中完成時一切都會更好。 – Cheeso 2009-06-03 12:11:42

回答

3

您可以在diredibuffer上標記文件並在其上查詢替換regexp。

for f in $(find . -name "*.cpp"); do 
    mv $f $f.bak 
    sed -e "s/old/new/g" $f.bak > $f 
done 
相關問題