- 论坛徽章:
- 0
|
回复 13# zxy877298415
非常感谢,该语句完美解决问题。感谢感谢!!!
在网上搜了一下正则表达式,稍微做了一下改造,这样就能匹配修改节点中的任何属性,而非端口类的数字了。谢谢谢谢!!!
[root@iZ11phehicpZ test]# cat server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
</Service>
</Server>
[root@iZ11phehicpZ test]# awk -vRS="/>" '/maxThreads="150"/{sub(/clientAuth="[^ \f\n\r\t\v]*"/,"clientAuth=\"true\"",$0)}{printf $0RT}' server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="true" sslProtocol="TLS" />
</Service>
</Server>
[root@iZ11phehicpZ test]# awk -vRS="/>" '/sslProtocol="TLS"/{sub(/port="[^ \f\n\r\t\v]*"/,"port=\"18888\"",$0)}{printf $0RT}' server.xml
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="18888" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
</Service>
</Server>
[root@iZ11phehicpZ test]# |
|