Extract values from xml file, bash -
i need parsing xml file in shell script, need extract values given xml file, , put them variables. here part of xml file
<?xml version="1.0" encoding="iso-8859-1"?> <!doctype site system "siteequipment.dtd" > <!-- site equipment configuration --> <site> <format revision="ak5" /> <optionalequipmentconfiguration configuresau="no" absolutetimesynchenabled="no" gpsoutenabled="false" smokedetector="false" /> <sitelocationconfiguration sitename="alzey002" logicalname="fxu046" > <sectordata sectornumber="1" latitude="4635826" lathemisphere="north" longitude="377963" geodatum="dhdn-" beamdirection="060" height="3000" sectorgroup="-1" /> <sectordata sectornumber="2" latitude="4635826" lathemisphere="north" longitude="377963" geodatum="dhdn-" beamdirection="140" height="3000" sectorgroup="-1" /> <sectordata sectornumber="3" latitude="4635826" lathemisphere="north" longitude="377963" geodatum="dhdn-" beamdirection="300" height="3000" sectorgroup="-1" /> </sitelocationconfiguration> <sectorcapabilitysettings> <sectorcapability radiobuildingblock="rbb12_1a" cprilinerate="ox4" sectornumber="1" primaryportid="bu1_a" sectorsequencenumber="1" rruinstalled="no" /> <sectorcapability radiobuildingblock="rbb12_1a" cprilinerate="ox4" sectornumber="2" primaryportid="bu1_b" sectorsequencenumber="1" rruinstalled="no" /> <sectorcapability radiobuildingblock="rbb12_1a" cprilinerate="ox4" sectornumber="3" primaryportid="bu1_c" sectorsequencenumber="1" rruinstalled="no" /> </sectorcapabilitysettings> <sectorequipmentconfiguration> <tmaconfiguration> <tmasector sectornumber="1" tmatype="none" tmatype2="none" tmatype3="none" typeofret="retu" typeofret2="none" typeofret3="none" riuinstalled="no" riuinstalled2="no" currentlowsupervision_a="on" currentlowsupervision_b="on" currentlowsupervision_c="on" currentlowsupervision_d="on" /> <tmasector sectornumber="2" tmatype="none" tmatype2="none" tmatype3="none" typeofret="retu" typeofret2="none" typeofret3="none" riuinstalled="no" riuinstalled2="no" currentlowsupervision_a="on" currentlowsupervision_b="on" currentlowsupervision_c="on" currentlowsupervision_d="on" /> <tmasector sectornumber="3" tmatype="none" tmatype2="none" tmatype3="none" typeofret="retu" typeofret2="none" typeofret3="none" riuinstalled="no" riuinstalled2="no" currentlowsupervision_a="on" currentlowsupervision_b="on" currentlowsupervision_c="on" currentlowsupervision_d="on" /> </tmaconfiguration> <antennaconfiguration> <antennasector sectornumber="1" antennatype="2" antennatype2="0" antennatype3="0" mechanicaltilt="0" mechanicaltilt2="0" mechanicaltilt3="0" electricaltilt="30" band="1" fqbandhighedgebrancha="21250" fqbandlowedgebrancha="21100" fqbandhighedgebranchb="21250" fqbandlowedgebranchb="21100" fqbandhighedgebranchc="" fqbandlowedgebranchc="" fqbandhighedgebranchd="" fqbandlowedgebranchd="" fqbandhighedgebranche="" fqbandlowedgebranche="" fqbandhighedgebranchf="" fqbandlowedgebranchf="" dlfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" sectoroutputpower="60" beamdirection="060" beamdirection2="000" beamdirection3="000" /> <antennasector sectornumber="2" antennatype="2" antennatype2="0" antennatype3="0" mechanicaltilt="0" mechanicaltilt2="0" mechanicaltilt3="0" electricaltilt="0" band="1" fqbandhighedgebrancha="21250" fqbandlowedgebrancha="21100" fqbandhighedgebranchb="21250" fqbandlowedgebranchb="21100" fqbandhighedgebranchc="" fqbandlowedgebranchc="" fqbandhighedgebranchd="" fqbandlowedgebranchd="" fqbandhighedgebranche="" fqbandlowedgebranche="" fqbandhighedgebranchf="" fqbandlowedgebranchf="" dlfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" sectoroutputpower="60" beamdirection="140" beamdirection2="000" beamdirection3="000" /> <antennasector sectornumber="3" antennatype="2" antennatype2="0" antennatype3="0" mechanicaltilt="0" mechanicaltilt2="0" mechanicaltilt3="0" electricaltilt="60" band="1" fqbandhighedgebrancha="21250" fqbandlowedgebrancha="21100" fqbandhighedgebranchb="21250" fqbandlowedgebranchb="21100" fqbandhighedgebranchc="" fqbandlowedgebranchc="" fqbandhighedgebranchd="" fqbandlowedgebranchd="" fqbandhighedgebranche="" fqbandlowedgebranche="" fqbandhighedgebranchf="" fqbandlowedgebranchf="" dlfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybrancha="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederattenuationbranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" dlfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" ulfeederdelaybranchb="0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1" sectoroutputpower="60" beamdirection="300" beamdirection2="000" beamdirection3="000" /> </antennaconfiguration> <initiatesectorsconfiguration> <initiatedsector sectornumber="1" antennasupervisionbrancha="10" antennasupervisionbranchb="10" antennasupervisionbranchc="0" antennasupervisionbranchd="0" antennasupervisionbranche="0" antennasupervisionbranchf="0" /> <initiatedsector sectornumber="2" antennasupervisionbrancha="10" antennasupervisionbranchb="10" antennasupervisionbranchc="0" antennasupervisionbranchd="0" antennasupervisionbranche="0" antennasupervisionbranchf="0" /> <initiatedsector sectornumber="3" antennasupervisionbrancha="10" antennasupervisionbranchb="10" antennasupervisionbranchc="0" antennasupervisionbranchd="0" antennasupervisionbranche="0" antennasupervisionbranchf="0" /> </initiatesectorsconfiguration> <localcellconfiguration carrierallocationmode="flexible" > <sector sectornumber="1" > <cell cellnumber="1" cellcreated="yes" cellidentity="461" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="2" cellcreated="yes" cellidentity="465" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="3" cellcreated="yes" cellidentity="468" cellrange="35000" basebandpoolid="1" numberoftxbranches="1" numberofrxbranches="2" /> </sector> <sector sectornumber="2" > <cell cellnumber="1" cellcreated="yes" cellidentity="462" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="2" cellcreated="yes" cellidentity="466" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="3" cellcreated="yes" cellidentity="469" cellrange="35000" basebandpoolid="1" numberoftxbranches="1" numberofrxbranches="2" /> </sector> <sector sectornumber="3" > <cell cellnumber="1" cellcreated="yes" cellidentity="463" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="2" cellcreated="yes" cellidentity="467" cellrange="35000" basebandpoolid="2" numberoftxbranches="1" numberofrxbranches="2" /> <cell cellnumber="3" cellcreated="yes" cellidentity="460" cellrange="35000" basebandpoolid="1" numberoftxbranches="1" numberofrxbranches="2" /> </sector> </localcellconfiguration> </sectorequipmentconfiguration
so need extract values examle, cellidentity
value's under each sector data
sector 1 var1=461 var2=465 var3=468 sector 2 var4=462 var5=466 var6=469 sector 3 var7=463 var8=467 var9=460
i tried xmllint errors:
/usr/bin/xmllint --shell 1.xml <<<"cat/<site/localcellconfiguration/sector/cell/cellidentity/" | grep -v "^/ >"
well i'm not familiar xmllint, need see how it's working can extract other values file. thank
*strong text*this might close:
awk -f\" '/sectornumber/{x="sector:" $2 rs} /cellidentity/{x=x $2 rs} /\<\/sector/{printf x}' file
output:
sector:1 461 465 468 sector:2 462 466 469 sector:3 463 467 460
if sectornumber
seen, output variable x
created sector number field 2. if cellidentity
seen, picked , appended x
separator. if </sector
encountered, output variable printed.
edited
if want values in variables, or better, array a
, this:
a=($(awk -f\" '/sectornumber/{x=$2 rs}/cellidentity/{x=x $2 rs}/\<\/sector/{printf x}' file)) echo ${a[0]} 3 echo ${a[1]} 1 echo ${a[2]} 461 echo ${a[3]} 465
Comments
Post a Comment