[sed]字符串替换

 

只替换文本文件中的第一个串

sed -i '0,/oldstring/s/oldstring/newstring/' file

只替换文本文件中第一次某个串后的内容, 把第一个title后卖弄的"abcdefg"替换成"hello",原始文本如下

12445676
title abcdefg
cotent test11111
title 1234567

方法

sed '0,/title/ s/\(title \).*/\1hello/' file

 

posted @ 2018-01-18 10:17  aaronGao  阅读(357)  评论(0编辑  收藏  举报