Reputation: 1013
I have a xml file with a same tag occuring multiple times continuously. I need to extract only that set of tags as an array.
xml file looks like:
...
<otherTags>
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
<otherTags>
...
My output should look like:
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
Upvotes: 0
Views: 1815
Reputation: 72747
If the format is that simple, use
$ awk '/<myTag>/,/<\/myTag>/' inputfile
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
<myTag>
<abc/>
</myTag>
But there are tools designed for parsing complex XML files, which you should use if it gets more complicated. One is called xml-grep. You might also want to familiarize yourself with XPath technology.
Upvotes: 1