shell -sed查找和替换文件中的内容

孤人 提交于 2019-11-28 17:12:03

sed查找和替换文件中的内容

 

sed -i 's/text/replace/' file

 

 

指定位置替换内容

echo thisthisthisthis |sed 's/this/THIS/3'

 

移除文件中的空白行 ^$

sed '/^$/d' file

 

子串匹配标记(\1)

echo this is digit 7 in a number | sed 's/digit \([0-9]\)/\1/'

 

多个匹配

echo abc | sed 's/a/A/' | sed 's/c/C/'

echo abc | sed 's/a/A/;s/c/C/'

 

echo abc | sed -e 's/a/A/' -e 's/c/C/'

 

 

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!