I am parsing a log file, loaded with many types of XMLs. I am using awk to extract a specific part of a XML. I am using the following:
awk '/<TAG>/,/<\/TAG>/' ${LOG} > OUTPUT.txt;
However, because these are inner tags and not the beginning or end of the XML as a whole (because there are multiple types of XMLs), I need to add the initial tag as well as closing tag at the bottom (to complete the log since the top and bottom tags are generic for all kinds of XMLs and I want a specific kind).
The question is:
Is there a way I can add text before and after each awk iteration?
example:
Input:
<TAG>
<InnerTAG>
</InnerTAG>
</TAG>
<TAGTWO>
<InnerTAG>
</InnerTAG>
</TAGTWO>
<TAG>
<InnerTAG>
</InnerTAG>
</TAG>
Output:
TOP
<TAG>
<InnerTAG>
</InnerTAG>
</TAG>
BOTTOM
TOP
<TAG>
<InnerTAG>
</InnerTAG>
</TAG>
BOTTOM
Where TOP & BOTTOM are two different prints or something that I added?
PS: I have no way to know how many iterations there are in advance... this is also dynamic per file.
Thanks,