Chinaunix
标题:
如何获取XML指定内容
[打印本页]
作者:
liucheng1513
时间:
2019-04-11 11:52
标题:
如何获取XML指定内容
如何分别获取 2542 2018-09-26 004 和 2018-09-26 23:30:39,这些数据不是固定值。
version=2542
date=2018-09-26
group=004
createTime=2018-09-26 23:30:39
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Bus version="2542" date="2018-09-26" group="004" createTime="2018-09-26 23:30:39">
<Play>
<Name>传媒总宣Name>
<Type>节目</Type>
<FileName>A390A15FEF2BD3DE2905E9A25881BF9A.mp4</FileName>
<Size>11692742</Size>
<Long>59</Long>
<Start>00:00:00</Start>
<ContractID></ContractID>
</Play>
<Play>
<Name>赞着看</Name>
<Type>节目</Type>
<FileName>ACACF15B7E7A7FC16D57633F4E6D8426.mp4</FileName>
<Size>43174643</Size>
<Long>206</Long>
<Start>00:00:59</Start>
<ContractID></ContractID>
</Play>
</Bus>
作者:
jzsjm1002
时间:
2019-04-11 13:16
本帖最后由 jzsjm1002 于 2019-04-11 14:37 编辑
[root@vh120 mnt]# cat test.sh
#!/bin/bash
#
path=/mnt/a00.xml
reg(){
grep -oP "<[^>]+$1=\"\K[^\"]+(?=\"\s*[dgc>])" $path
}
version=`reg version`
date=`reg date`
group=`reg group`
createTime=`reg createTime`
echo "version=$version"
echo "date=$date"
echo "group=$group"
echo "createTime=$createTime"
[root@vh120 mnt]# ./test.sh
version=2542
date=2018-09-26
group=004
createTime=2018-09-26 23:30:39
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2