替换SED XML值 [英] replace xml value with sed

查看:800
本文介绍了替换SED XML值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想换成XML文件中的值。示例XML

 <游戏机和GT;
                <! - 所需的参数 - >
                <! - 输入您从中运行安装程序的节点。此值必须是一个完全合格的名称,其中包括主机名和域名。例如,node001.server.name.com .-->
                <节点> node.sample.ibm.com< /节点>                <! - 输入集群作为一个单一的点分隔字符串的域名。例如,server.name.com。 - >
        < SSO的域的名称>&sample.ibm.com LT; / SSO的域的名称>        <! - 这个属性,如果你的的InfoSphere BigInsights控制台使用HTTPS设置为true。否则,输入错误的。 - >
                <&HTTPS GT假LT; / HTTPS>        <! - 管理的控制台端口指定的端口所使用的管理控制台。 - >
        <管理控制台端口> 8080< /管理控制台端口>

我想,以取代的​​价值。
我试着用以下但不工作。任何帮助AP preciated。

  SED -i/<控制台> /,/< \\ /控制台> / S /<节点> [0-9] [AZ] \\ + /<节点> NEWVALUE


解决方案

 的sed -i -e'/<控制台> /,/< \\ /控制台> / S |&LT ;节点> [0-9A-Z] \\ {1,\\}< /节点> |<节点>&NEWVALUE LT; /节点> | G'YourFile

我假设值是您的标记和之间只包含(根据您的样品和试试)小写字母,点和数字。如果扩展,只要添加字符类缺少像 [0-9A-Z ._- A-Z:] ,也许子类[:空间:]

如果 NEWVALUE 是一个变量的内容,不要忘了使用双引号和转义符&安培; \\ 和sed 取值动作(默认为 / 的分离和 | 在我的code)

I would like to replace value in XML file. Sample 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>

I would like to replace value. I tried with following but its not working. Any help appreciated.

sed -i "/<Console>/,/<\/Console>/ s/<node>[0-9][a-z]\+/<node>newvalue

解决方案

sed -i -e '/<Console>/,/<\/Console>/ s|<node>[0-9a-z.]\{1,\}</node>|<node>newvalue</node>|g' YourFile

i assume value is between your tag and and only contain small letter, dot and digit (based on your sample and try). If extended, just add character missing in the class like [0-9a-z._-A-Z:] and maybe sub-class [:space:]

if newvalue is a variable content, dont forget to use double quote and escape character &, \ and the separator of sed s action (default is / and | in my code)

这篇关于替换SED XML值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆