Jeel Jeel - 5 months ago 8
Bash Question

Shell script to extract value for a variable from XML response

I have a XML response from which I need to extract the value of ObjDevice whenever the BillPlan="UBM - A/A". Can you please help me with a shell script to do the same

<Txn>
<TxnName>Spectrum-AlertSite-Component_spectrum.engprod_InstantUpgradeEdge_GetProductOffersByAccount_getProductOffersByAccountValid</TxnName>
<TxnDetail Monitor="y" Notify="y" PingError="n"
TraceError="y" Interval="5" TimeOut="300"
ObjDevice="318373" BillPlan="UBM - A/A" MaxSteps="50"

/>
</Txn>
<Txn>
<TxnName>Spectrum-AlertSite-Component_spectrum.engprod_InstantUpgradeEdge_GetProductOffersByAccount_getProductOffersByAccountValid</TxnName>
<TxnDetail Monitor="y" Notify="y" PingError="n"
TraceError="y" Interval="5" TimeOut="300"
ObjDevice="318377" BillPlan="UBM - A/A" MaxSteps="50"

/>

Answer

Well if you don't have a special tool to handle XML files and you always have in the same line both values then you can execute:

grep 'BillPlan="UBM - A/A"' | sed ',.*ObjDevice="\([0-9]*\)" BillPlan="UBM - A/A".*,\1,"

Sorry if I don't use sed to filter but not so familiar with sed and also don't have access to a *nix, but maybe somebody else can give us the short version

Comments