Hi ,
Please help me with the following problem:
I have an xml file with the following lines
<cisco:name>
<cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm>
<cisco:meNm>10.1.100.19</cisco:meNm>
<cisco:ehNm>/shelf=1</cisco:ehNm>
<cisco:subname>
<cisco:sptp>Cisco PortA Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort B Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
<cisco:subname>
<cisco:sptp>Cisco PortAB Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort AB Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
</cisco:name>
<cisco:name>
<cisco:mdNm>Cisco Device 7500B Series</cisco:mdNm>
<cisco:meNm>10.1.100.20</cisco:meNm>
<cisco:ehNm>/shelf=2</cisco:ehNm>
<cisco:subname>
<cisco:sptp>Cisco Port B Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort B Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
</cisco:name>
In My code it will first check the two strings <cisco:name> and </cisco:name> and after that it will grep the count of <cisco:cpt>. and so on continue till the end of file
#!/bin/sh
sed '/<\/cisco:name>/{G;}' test.xml >temp
nawk 'BEGIN{RS=""}
{
grep -c '<cisco:cpt>' print
}' temp
rm temp
this code is not giving the the op as
in first<cisco:name> and </cisco:name> loop it should give 2 then for next it would 1
plz help