我必须添加
<configuration>
<jsp-configuration
display-source-fragment="false"
x-powered-by="false"/>
</configuration>
匹配此图案线后
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
我如何使用sed命令实现这一点我尝试了一些像这样的
sed '/connector name="http" protocol="HTTP\/1.1" scheme="http" socket-binding="http"/a\ \<configuration>\n\<jsp-configuration display-source-fragment="false" x-powered-by="false"/>\n\</configuration> abc.xml
答案 0 :(得分:1)
此awk
将执行:
awk '/<connector name="http" protocol="HTTP\/1.1" scheme="http" socket-binding="http"\/>/ {$0=$0"\n<configuration>\n <jsp-configuration\n display-source-fragment=\"false\"\n x-powered-by=\"false\"/>\n </configuration>"}1' abc.xml
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<configuration>
<jsp-configuration
display-source-fragment="false"
x-powered-by="false"/>
</configuration>
或使用sed
sed '/<connector name="http" protocol="HTTP\/1.1" scheme="http" socket-binding="http"\/>/a <configuration>\n <jsp-configuration\n display-source-fragment=\"false\"\n x-powered-by=\"false\"/>\n </configuration>' abc.xml
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<configuration>
<jsp-configuration
display-source-fragment="false"
x-powered-by="false"/>
</configuration>
你离sed
很近,你最后错过'
和一些空格。