Chinaunix
标题:
在特定字符串后插入新的字符串
[打印本页]
作者:
done_and_todo
时间:
2012-10-10 11:33
标题:
在特定字符串后插入新的字符串
有一文件其格式如下:
<A>
<B></B>
<C></C>
</A>
在文件中A是唯一的,而B,C有多个,我想在<B>后插入新的字符串,不知有什么方法定位到<B>。
作者:
zhaopingzi
时间:
2012-10-10 12:52
sed "s/<B>/&newstring/g" file
作者:
done_and_todo
时间:
2012-10-10 13:20
本帖最后由 done_and_todo 于 2012-10-10 13:20 编辑
回复
2#
zhaopingzi
我只是想在<A>与</A>之间的<B>后插入字符串,并不想全文的<B>后插入。
作者:
kk5234
时间:
2012-10-10 13:28
回复
3#
done_and_todo
sed '/<A>/,/<\/A>/{s/<B>/&newstring/}'
作者:
done_and_todo
时间:
2012-10-10 13:42
回复
4#
kk5234
OK,Thank you.
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2