網絡技術日誌
關於 PHP, Linux, Open Source 及個人生活記載的網誌。
-
用 Perl 做 Search and replace
Posted on February 23rd, 2006 3 comments一些用靜態 HTML 編寫的網站,如果要將每一頁的特定文字更新 (例如 copyright),要逐頁逐頁更改真的十分麻煩。這個問題有幾個解決方法,其中一個是在指令模式用 perl 來做替換,例如:
perl -pi -e 's/src_str/new_str/g' *.html
以上指令會將目錄下所有 .html 尾的檔案更新,用 "new_str" 替換 "src_str"。
3 responses to “用 Perl 做 Search and replace”
-
如果使用dreamweaver中的搜尋取代也滿快的!!
-
johnpupu January 26th, 2007 at 11:51
謝謝你提供的方法。
-
Yong-jhih Chen August 10th, 2007 at 08:20
sed -i.bak ‘s/src_str/new_str/g’ *.html
sed -i.bak ‘s/src_str/new_str/g’ $(find . -name ‘*.html’ | xargs)
Leave a reply
-
