zoukankan      html  css  js  c++  java
  • shell解决xml文本中筛选的问题

    shell解决xml文本中筛选的问题,将xml文件中多余的配置删除掉,达到符合单一配置的结果。

    过于简单就不废话了。

    #!/bin/bash
    
    conf_file=$1
    flag=0
    temp_file="__temp.xml"
    
    if [ -f "${temp_file}" ];then
        rm "${temp_file}"
    fi
    while read line
    do
        echo "${line}" | grep '<connection' > /dev/null
        if [ $? = 0 ];then
            flag=1
            echo "${line}"
            echo "${line}" >> "${temp_file}"
            continue
        fi
        echo "${line}" | grep '</connection' > /dev/null
        if [ $? = 0 ];then
            flag=0
            echo "${line}"
            echo "${line}" >> "${temp_file}"
            continue
        fi
        echo "${line}" | grep '<server' > /dev/null
        if [ $? = 0 -a ${flag} = 1 ];then
            flag=2
            echo "${line}"
            echo "${line}" >> "${temp_file}"
            continue
        elif [ $? = 0 -a ${flag} = 2 ];then
            continue
        fi
        if [ ${flag} = 0 ];then
            echo ${line} >> "${temp_file}"
        fi
    done < ${conf_file}

    然而在其他的解决方式中,也可以通过awk脚本直接将结果进行统一的处理

    比如:

    awk '!/<server ip=/{print;c=0}   /<server ip=/ && ++c==1{print}' xxx.xml > __temp.xml

    可以自己找一个xml文本进行自我的体验。

    真正的结果一定要自己体验,否则就没有意义。

  • 相关阅读:
    C# 中==和Equal的区别
    3dmath复习随笔
    3dmax学习资料记录
    [官方教程] Unity 5 BLACKSMITH深度分享
    [技术] [插件精选] 炫酷粒子特效(下)
    Unity3D总结:关于射线碰撞
    Unity3D将来时:IL2CPP(上)
    3DMAX 9 角色建模3 uv展开
    php,c# hamsha1
    U3D 的一些基础优化
  • 原文地址:https://www.cnblogs.com/wozijisun/p/14776393.html
Copyright © 2011-2022 走看看