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文本进行自我的体验。

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

相关推荐
w678200717 小时前
,攻击者通过构造特殊的XML使其包含恶意外部实体。外部实体可以为服务器敏感文件,也可以为网络请求等,之后利用方式类似于文件包含和SS ...
xml·服务器·网络
name好难取诶20 小时前
解析请求体内容(如 JSON、表单数据、XML 等) 将原始数据转换为 Python 数据结构 使转换后的数据可在 request. ...
xml·python·json
qq_1715388521 小时前
深入浅出 MyBatis XML:从入门到精通
xml·java·mybatis
前网易架构师-高司机7 天前
带标注的扑克牌识别数据集,识别率99.5%,3083张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·数字·扑克牌·纸牌
执明wa8 天前
LayoutInflater详解: XML是如何变成View的?
android·xml·开发语言·android studio
IT_Octopus10 天前
一次由 RestTemplate 引发的 Connection reset:被 XML 截胡的请求体
xml·java·spring boot
Dontla10 天前
网站爬虫控制策略介绍(robots.txt、sitemap.xml、x-robots-tag、noindex、nofollow)网站索引
xml·爬虫·dubbo
风起洛阳@不良使11 天前
spring中xml和注解开发的对比
xml·java·spring
Mikowoo00712 天前
批量汇总XML格式的发票信息
xml·python
逃逸线LOF12 天前
xml文件如何加载properties文件(spring容器加载properties文件)
xml