码迷,mamicode.com
首页 > 其他好文 > 详细

sed命令如何实现XML文件的增删改??急急急!哪位大神告诉下啊

时间:2014-11-11 13:59:35      阅读:384      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   color   ar   os   sp   文件   div   

<DC_Public>
    < Codec_Space Codec_SpaceValue="0" />
    < HeartBeatCfg HeartBeatRate="16" Mux_HB_DECount="2" Codec_HB_DECount="2" Prov_HB_DECount="2" />
    < DC_Public PathValue="dc_user.rft" DefaultUserName="administrator" DefaultUserPassword="12345678" PrivateData="PrivateData" />
    < CheckPW TheValue="1" />
    < Device_Info VideoInputNum="10" AudioInputNum="1" VideoOutputNum="4" AudioOutputNum="1" />
    < StreamTransport ConnectTimes="0" />
</DC_Public>
<DC_NetWork>
    < Codec_SockControl Codec_IP="192.168.240.240" Codec_CtrPort="3300" Codec_UDPHeartPort="27229" Codec_LogPort="27235" Link_Internal_Codec="eth2" />
    < Mux_SockControl Mux_LogPort="27235" Mux_CtrPort="5000" Mux_IP="192.168.230.230" />
    < LinkCfg Link_Internal_Mux="eth1" Link_OutSide="eth3" Link_Internal_Codec="eth2" />
    < ControlListen ListenPort="2000" />
</DC_NetWork>
<DC_SerialProt>
    < Port1 PortUsage="3" PortEnable="1" PortDevAddr="/dev/ttyS0" PortBaudrate="9" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
    < Port2 PortUsage="2" PortEnable="1" PortDevAddr="/dev/ttyS1" PortBaudrate="9" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
    < Port3 PortUsage="4" PortEnable="1" PortDevAddr="/dev/ttyS2" PortBaudrate="9" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
    < Port4 PortUsage="5" PortEnable="1" PortDevAddr="/dev/ttyS3" PortBaudrate="9" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
    < Port5 PortUsage="7" PortEnable="1" PortDevAddr="/dev/ttyS4" PortBaudrate="13" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
    < Port6 PortUsage="1" PortEnable="1" PortDevAddr="/dev/ttyS5" PortBaudrate="9" PortByteSize="4" PortParity="0" PortStopBit="1" FlowControl="0" />
</DC_SerialProt>
<OSDManageMoudle>
    < OSDBaseInfo InputOSDCount="10" />
    < InputOSD_ID1 OSD_Script="Input1" InputVSID="1" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID2 OSD_Script="Input2" InputVSID="2" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID3 OSD_Script="Input3" InputVSID="3" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID4 OSD_Script="Input4" InputVSID="4" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID5 OSD_Script="Input5" InputVSID="5" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID6 OSD_Script="Input6" InputVSID="6" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID7 OSD_Script="Input7" InputVSID="7" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID8 OSD_Script="Input8" InputVSID="8" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID9 OSD_Script="Input9" InputVSID="9" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < InputOSD_ID10 OSD_Script="Input10" InputVSID="10" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < RemoteInputOSD OSD_Script="RemoteSource" InputVSID="0" FontSize="10" FontSpace="0" Position="1" RedColor="255" GreenColor="255" BlueColor="255" Enable="0" />
    < _TimeOSDBaseInfo1 Xpos="0" Ypos="0" RedColor="0" GreenColor="0" BlueColor="0" Enable="0" />
    < BackgroundBaseInfo Enable="0" />
    < _TimeOSDBaseInfo2 Xpos="0" Ypos="0" RedColor="0" GreenColor="0" BlueColor="0" Enable="0" />
    < RemoteSource Enable="1" />
</OSDManageMoudle>

例如我要增加节点DC_SerialProt的子节点Port2的属性 ProtSize="56" 用sed命令如何做呢,首先我得定位节点DC_SerialProt的内容,然后再其中定位子节Port2,然后才能添加属性,改如何做啊。。。大神教教吧bubuko.com,布布扣 返回IT界网站首页>>

--------解决方案--------
参见我的博客:http://blog.csdn.net/zmlovelx/article/details/21158235
--------解决方案--------
再问下大神,如果我想判断XML里有没有某个字符串

if   sed -n ‘/XXX/p‘ 1.xml >/dev/null 2>&1;then
 echo "hello"
else
echo "world"
 fi
应该是XXX字符串存在 打印出hello  XXX不存在打印world
为什么无聊XXX存不存在打印的都是hello啊  请问哪里出错了啊
--------解决方案--------

sed -n ‘/XXX/p‘ 1.xml
不管是否存在XXX,sed命令都认为自己成功执行完毕。

改成grep吧
grep ‘XXX‘ 1.xml
--------解决方案--------
谢啦 大神 。
文章来源:IT界 http://www.itjie.wang/linuxdevelopment/504493.html

sed命令如何实现XML文件的增删改??急急急!哪位大神告诉下啊

标签:blog   http   io   color   ar   os   sp   文件   div   

原文地址:http://www.cnblogs.com/happysean/p/4089115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!