I have a scenario wherein a file contains xml tags. There is a tag like <abcd .... param="paramvalue"> under which I have another tag named <efgh="value"> under which another tag <hijk> is present. I need to count the no. of <hijk> tags present in each <abcd> tag and I have to display the value of param in <abcd> tag and value of <efgh> tag.
For example,
FILENAME.xml
<abcd...... xyz="value1">
<efgh="value2">
<hijk>
....
</hijk>
....
</efgh>
<efgh="value3">
....
</efgh>
....
</abcd>
<abcd...... xyz="value4">
.......
</abcd>
......
I used
sed -n '/xyz=*/p' FILENAME.xml | cut -d = -f 4 | echo "xyz:` cut -d " " -f 1`" && sed -n '/efgh=*/p' FILENAME.xml | cut -d = -f 2 | echo "efgh:`cut -d " " -f 1`" && grep -c '`<hijk>`' FILENAME.xml
But I got the total count of <hijk> tags and got a separate list of xyz values and a separate list of efgh values.
I need the solution in this format,
xyz="value1"
efgh="value2"
no. of hijk tags
....
xyz="valueN"
efgh="valueN"
no. of hijk tags
....
and so on.
And I thought I could use 3 inner loops along with sed command to iterate. Am I correct? Even if I am, I need help doing so. Please help.
No comments:
Post a Comment