我想将我的xml"abc.xml"元素的值更改为存储在变量$ value ie中的值
$ value ='abc';
<annotation>
    <filename>img_000001016592.png</filename>
    <folder>Rec_20121219_171905</folder>
    <source>
        <sourceImage>The MIT-CSAIL database of objects and scenes</sourceImage>
        <sourceAnnotation>LabelMe Webtool</sourceAnnotation>
    </source>
    <imagesize>
        <nrows>481</nrows>
        <ncols>640</ncols>
    </imagesize>
</annotation>
需要shell脚本,它有一个变量,它包含变量中的值,然后将abc.xml的元素文件名的值更改为变量中的值.
我想替换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 …我的Linux机器上有一个XML文件MyFile.xml。
<?xml version="1.0" encoding="UTF-8"?>
  <project>
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.mycompany</groupId>
              <env name="envvar" value="/opt/environment/environment.properties" />
              <env name="JDBC_Driver"  value="/opt/JDBC/ojdb6.jar" />
              <env name="agent/enable" value="true" />
</project>
每当我有需求时,我都需要将XML文件中的标记的值更改为"false"(当它为true时)和"true"(当它为false时)env name="agent/enable"。
我只是想为此使用一些shell脚本。我知道这可以在Linux中使用Sed命令来完成,但是我不擅长正则表达式。这样,每当我有更改要求时,我都可以运行脚本。
注意:脚本应更改XML文件,并应使用相同的名称保存在文件系统中。