linux下替換所有包含指定內容的文件

http://stackoverflow.com/questions/15920276/find-and-replace-string-in-all-files-recursive-using-grep-and-sed



在指定目錄下將所有包含app\components替換成oss\components

mac下格式:

grep -rl 'app\\components' /Users/peter/home/workspace/oss/oss/models | xargs sed -i "" s#app\\\\components#oss\\\\components#g


其他linux:

grep -rl 'app\\components' /Users/peter/home/workspace/oss/oss/models | xargs sed s#app\\\\components#oss\\\\components#g



mac用sed寫幾個文本替換,用-i參數原地替換,發現不行。糾結了一下。

man sed

發現 -i 需要帶一個字符串,用來備份源文件,這個字符串加在源文件名後面組成備份文件名。

如果這個字符串長度爲0,就是說是個空串,那麼不備份。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章