I have a big XML file and I get all occurrences between 2 tags:
Here is what I do:
sed -n '/<tag>/,/<\/tag>/p' file.xml
And I need to filter to get only first N occurrences. I've tried with l param but it was not enough :(
So any one knows how to get N matched occurrences from all resultset?
For Example. Here the xml file content :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>
</root>
sed -n '/<tag>/,/<\/tag>/p' file.xml
returns all elements.
So the goal is to filter to get the First n matched patterns ( Elements are multi-line) If n = 2 then result =:
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>
<tag>
<t1>john</t1>
<t2>john</t2>
<t3>john</t3>
</tag>