shell,sed修改指定位置的文本中的指定内容
/b/xx 即在目录b下存在一个文件xx,文件xx的内容如下
<Host>
123224rsiskd1
sdfkldsfjkslf2
fdsjlfjlsdf3
fdjsofjs;f4
fjdsfdksfkd5
dsfkjgds6
</Host>
现在,我想在</Host>的前面一行,也就是 dsfkjgds6 和</Host>之间添加一行文字,文字如下
<Valve className ="a.b.c.d.e"/>
请问应该如何写?
[解决办法]
[root@RHEL6A tmp]# cat data7.txt <Host>123224rsiskd1sdfkldsfjkslf2fdsjlfjlsdf3fdjsofjs;f4fjdsfdksfkd5dsfkjgds6</Host>[root@RHEL6A tmp]# awk '{if ($0=="<Host>") printf("%s\n<Valve className =\"a.b.c.d.e\"/>\n",$0);else print $0}' data7.txt <Host><Valve className ="a.b.c.d.e"/>123224rsiskd1sdfkldsfjkslf2fdsjlfjlsdf3fdjsofjs;f4fjdsfdksfkd5dsfkjgds6</Host>[root@RHEL6A tmp]#