• shell解析xml文件


    centos安装xml2

    yum install xml2
    

    测试文件

        <?xml version="1.0" encoding="UTF-8" ?>
        <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    
        <properties>
            <comment>
                PowerEngine Main Configuration
            </comment>
            <entry key="CurrentMode">Mode.DEV</entry>
    
            <entry key="Mode.DEV">
                classpath:/config/mode/dev/peconfig.xml
            </entry>
    
            <entry key="Mode.TEST">
                classpath:/config/mode/test/peconfig.xml
            </entry>
    
            <entry key="Mode.PRO">
                classpath:/config/mode/pro/peconfig.xml
            </entry>
    
            <entry key="Mode.UAT">
                classpath:/config/mode/uat/peconfig.xml
            </entry>
            <entry key="CommonConfig">
                classpath:/config/pe/*.xml
                classpath:/config/dubbo/*.xml,
                classpath:/config/trs/*.xml,
                classpath:/config/db/*.xml
            </entry>
    

    解析文件并替换内容

    xml2 < test.xml > test.txt
    sed -i 's#/properties/entry=Mode.DEV#/properties/entry=Mode.PRO#g' test.txt
    
    /properties/comment=
    /properties/comment=        PowerEngine Main Configuration
    /properties/comment=
    /properties/entry/@key=CurrentMode
    /properties/entry=Mode.DEV
    /properties/entry
    /properties/entry/@key=Mode.DEV
    /properties/entry=
    /properties/entry=		classpath:/config/mode/dev/peconfig.xml
    /properties/entry=
    /properties/entry
    /properties/entry/@key=Mode.TEST
    /properties/entry=
    /properties/entry=		classpath:/config/mode/test/peconfig.xml
    /properties/entry=
    /properties/entry
    /properties/entry/@key=Mode.PRO
    /properties/entry=
    /properties/entry=		classpath:/config/mode/pro/peconfig.xml
    /properties/entry=
    /properties/entry
    /properties/entry/@key=Mode.UAT
    /properties/entry=
    /properties/entry=		classpath:/config/mode/uat/peconfig.xml
    /properties/entry=
    /properties/entry
    /properties/entry/@key=CommonConfig
    /properties/entry=
    /properties/entry=		classpath:/config/pe/*.xml
    /properties/entry=		classpath:/config/dubbo/*.xml,
    /properties/entry=		classpath:/config/trs/*.xml,
    /properties/entry=		classpath:/config/db/*.xml
    /properties/entry=
    

    恢复为xml格式文件

    echo '<?xml version="1.0" encoding="UTF-8" ?>' > test.xml
    echo '<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">' >> test.xml
    2xml < test.txt >> test.xml
    
  • 相关阅读:
    记一次跳转
    html2canvas在生成图片过程中遇到的坑vue
    数组对象push新的元素,导致其他新复制的数据也发生改变,不是一一对应改变(深拷贝和浅拷贝)
    js生成的新结构点击事件不生效
    箭头函数和普通函数的区别
    vue (vue-cli主要写构建工具的使用)
    favicon.ico可能会遇到的的坑
    video不能在个别浏览器不能播放
    a标签的拨打电话、发邮件、QQ发消息,另外控件分享转发
    git使用的简单命令
  • 原文地址:https://www.cnblogs.com/peitianwang/p/11304598.html
Copyright © 2020-2023  润新知