我想替换XML文件中的值.示例XML
<Console>
<!-- REQUIRED PARAMETERS -->
<!-- Enter the node that you are running the installation program from. This value must be a fully qualified name, which includes a host name and domain name. For example, node001.server.name.com.-->
<node>node.sample.ibm.com</node>
<!-- Enter the domain name of the cluster as a single dot-separated string. For example, server.name.com. -->
<sso-domain-name>sample.ibm.com</sso-domain-name>
<!-- Set this property to true if your InfoSphere BigInsights Console uses HTTPS. Otherwise, enter false. -->
<https>false</https>
<!-- management-console-port specifies which port is used by the Management Console. -->
<management-console-port>8080</management-console-port>
Run Code Online (Sandbox Code Playgroud)
我想取代价值.我尝试了以下,但它不起作用.任何帮助赞赏.
sed -i "/<Console>/,/<\/Console>/ s/<node>[0-9][a-z]\+/<node>newvalue
Run Code Online (Sandbox Code Playgroud)
sed -i -e '/<Console>/,/<\/Console>/ s|<node>[0-9a-z.]\{1,\}</node>|<node>newvalue</node>|g' YourFile
Run Code Online (Sandbox Code Playgroud)
我假设价值在您的标签之间,并且只包含小写字母,点和数字(基于您的样本和尝试).如果扩展,只需在类中添加缺少的字符[0-9a-z._-A-Z:],也许子类[:space:]
如果newvalue是一个变量的内容,不要忘了使用双引号和转义字符&,\和sed的分离s动作(默认是/和|我的代码)
你可以使用xmlstarlet:
xmlstarlet ed -u //Console/node -v 'new value'
Run Code Online (Sandbox Code Playgroud)
(或类似的东西)
| 归档时间: |
|
| 查看次数: |
23778 次 |
| 最近记录: |