Sed替换删除添加字符串

来源:互联网 发布:软件测试行业如何 编辑:程序博客网 时间:2024/05/21 06:51

替换文本

# 替换当前目录下所有文本文件中,hello为world。i就地修改sed -i 's/hello/world' *.txt# 替换包含hello的文本为hi, r递归,l列出文件目录sed -i "s/hello/hi/g" `grep "hello" -rl ./`

删除文本行

# 删除包含insert的行sed -i '/insert/d' test.txt

添加字符串

# 查找包含hello的行,并在行首添加1,&表示匹配到的内容# 也可以使用\1-\9来匹配部分sed -i '/hello/s/^/1&/' test.html

参考

http://www.gnu.org/software/sed/manual/html_node/

原创粉丝点击