歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux sed命令替換文件文件內容

Linux sed命令替換文件文件內容

日期:2017/2/28 14:55:24   编辑:Linux教程

sed在Linux下是個強大的工具,這裡主要說替換:

1、替換並輸出(不修改源文件):

sed 's/dog/cat/g' file ##dog被替換的內容,cat替換的內容

2、備份後直接替換至源文件:

sed -i.bak 's/dog/cat/g' file

3、替換第n行到第m行:

sed 'n,ms/dog/cat/g' file ##n、m為數字

4、替換內容xxx和***之間的內容:

sed '/A/,/B/s/dog/cat/g' file ##替換A和B之間的內容

5、一次替換多個多個內容:

sed -e 's/dog1/cat1/g' -e 's/dog2/cat2/g' file

Copyright © Linux教程網 All Rights Reserved