我尽我所能得到这个,运气不好,我有以下文件,我想先替换 “<Connector port="8080"” xml block with ‘xxxx’
之前:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
之后:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
xxxx
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
我使用以下sed命令打印匹配的字符串:
sed -n '/<Connector port="8080"/,/>/p' filename
但是我无法开发它以获得高于输出 .
3 回答
在将连接器部分更改为xxxx之前加载连接器部分,这允许您最终对其进行测试(但如果没有,则不会比pobrelkey更好)
这个
sed
应该对您的示例输入进行操作(但如果您有多个<Connector port="8080"
部分,则会过于热心):但是处理这个问题需要一个XML解析器 . 例:
感谢所有的答案,他们运作良好 . 赞成它:我也从我的一个firend跟随也使用awk回答这个问题