我有一个下面提到的要求。
示例文件.txt ::
<?xml version='1.0' encoding='utf-8'?>
<Server port="${shutdown.port}" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="com.springsource.tcserver.serviceability.rmi.JmxSocketListener"
port="${jmx.port}"
bind="127.0.0.1"
useSSL="false"
passwordFile="${catalina.base}/conf/jmxremote.password"
accessFile="${catalina.base}/conf/jmxremote.access"
authenticate="true"/>
<Listener className="com.springsource.tcserver.serviceability.deploy.TcContainerDeployer" />
<GlobalNamingResources>
<Resource
name="jdbc/myDBPool1"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
description="Oracle Datasource"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@localhost:<dbanme>"
user="myusername"
password="somepassword1"
validationQuery="SELECT 1 FROM DUAL"
/>
<Resource
name="jdbc/myDBPool2"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
description="Oracle Datasource"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@localhost:<dbanme>"
user="myusername"
password="somepassword2"
validationQuery="SELECT 1 FROM DUAL"
/>
<Resource
name="jdbc/myDBPool3"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
description="Oracle Datasource"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@localhost:<dbanme>"
user="myusername"
password="somepassword3"
validationQuery="SELECT 1 FROM DUAL"
/>
</GlobalNamingResources>
<Service name="Catalina">
<Executor name="tomcatThreadPool" namePrefix="tomcat-http--" maxThreads="300" minSpareThreads="50"/>
<Connector executor="tomcatThreadPool"
port="${http.port}"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${https.port}"
acceptCount="100"
maxKeepAliveRequests="15"/>
<Engine name="Catalina" defaultHost="localhost">
<!--
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" deployOnStartup="true" deployXML="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
</Service>
</Server>
我正在尝试使用此脚本在两个字符串(包括字符串)之间查找一些文本(。密码。),然后将其替换为占位符。每当我的 cmdlinepasswd 占位符有特殊字符说“/”字符时,它就会失败。
sed -ie "/$datasource/,/password*/ {s/.*password.*/\tpassword=\"$cmdlinepasswd\"/;}" file.txt
假设 datasource=jdbc/myDBPool1 cmdlinepasswd=new/passwd
我是脚本新手,任何帮助将不胜感激。谢谢你。