linux sed 批量替換多個檔案中的字串

2021-04-13 07:39:29 字數 519 閱讀 7838

一、linux sed 批量替換多個檔案中的字串

sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir`

例如:替換/home下所有檔案中的www.bcak.com.cn為bcak.com.cn

sed -i "s/www.bcak.com.cn/bcak.com.cn/g" `grep www.bcak.com.cn

-rl /home`

二、下面這條命令:

perl -pi -e 's|abcd|linux|g' `find ./ -type f`

將呼叫perl執行一條替換命令,把find命令找到的所有檔案內容中的abcd替換為linux

find ./ -type f

此命令是顯示當前目錄下所有的檔案

上面的「s|abcd|linux| g」是perl要執行的指令碼,即把所有abcd替換為linux

如果不寫最後的那個g,「s|abcd|linux| 」將只替換每一行開頭的abcd 

linux sed 批量替換字串

一月 21,2014 no comments linux下批量替換多個檔案中的字串的簡單方法。用sed命令可以批量替換多個檔案中的字串。命令如下 sed i s 原字串 新字串 g grep 原字串 rl 所在目錄 例如 我要把 charset gb2312 替換為 charset utf 8,執行...

linux sed 批量替換字串

inux下批量替換多個檔案中的字串的簡單方法。用sed命令可以批量替換多個檔案中的字串。命令如下 sed i s 原字串 新字串 g grep 原字串 rl 所在目錄 解釋一下 i 表示inplace edit,就地修改檔案 r 表示搜尋子目錄 l 表示輸出匹配的檔名 這個命令組合很強大,要注意備份...

linux sed 批量替換字串

linux下批量替換多個檔案中的字串的簡單方法。用sed命令可以批量替換多個檔案中的字串。命令如下 sed i s 原字串 新字串 g grep 原字串 rl 所在目錄 例如 我要把 charset gb2312 替換為 charset utf 8,執行命令 sed i s charset gb23...