相关疑难解决方法(0)

用于更改xml元素的shell脚本

我想将我的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>
Run Code Online (Sandbox Code Playgroud)

需要shell脚本,它有一个变量,它包含变量中的值,然后将abc.xml的元素文件名的值更改为变量中的值.

xml bash shell

5
推荐指数
1
解决办法
1万
查看次数

用sed替换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 …
Run Code Online (Sandbox Code Playgroud)

xml bash sed

4
推荐指数
2
解决办法
2万
查看次数

在XML文件中替换特定标签的值

我的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>
Run Code Online (Sandbox Code Playgroud)

每当我有需求时,我都需要将XML文件中的标记的值更改为"false"(当它为true时)和"true"(当它为false时)env name="agent/enable"

我只是想为此使用一些shell脚本。我知道这可以在Linux中使用Sed命令来完成,但是我不擅长正则表达式。这样,每当我有更改要求时,我都可以运行脚本。

注意:脚本应更改XML文件,并应使用相同的名称保存在文件系统中。

xml linux sed

1
推荐指数
1
解决办法
8040
查看次数

标签 统计

xml ×3

bash ×2

sed ×2

linux ×1

shell ×1