歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> sed替換文本中的內容

sed替換文本中的內容

日期:2017/3/1 14:56:16   编辑:關於Linux
sed替換文本中的內容 linux 的shell是個很強大的東西。 用sed命令可以很輕松的將文件中的東西替換成自己想要的內容。 例如,有一個測試文件test,裡面的xxx作為要替換的內容。 hello world! this is a document that used to test sed! here i have a simbol xxx, the simbol xxx is a location used to be replaced. 把上面文件中的xxx替換成昨天的日期 sed -e "s/xxx/`date -d "1 day ago" +%Y%m%d`/g" > testsedresult 結果就為 hello world! this is a document that used to test sed! here i have a simbol 20130825, the simbol 20130825 is a location used to be replaced. sed 後面跟的字符串 "s/ 源內容/ 目標內容 /g" 表示替換的內容,還可以用正則表達式來匹配源內容
Copyright © Linux教程網 All Rights Reserved