Skip to main content
5 of 10
Rollback to Revision 2
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

Extract data between two xml tag using sed or awk and print on one line

Extract data between two xml tag.

Xml File:

<instance ab=1 >
<a1>a1</a1>
    <a2>a2</a1>
</instance>
<instance ab=2 >
<b1>a1</b1>
    <b2>a2</b1>
</instance>
<instance ab=3 >
<c1>a1</c1>
    <c2>a2</c2>
</instance>

Looking for output by using sed or awk like following.

<a1>a1</a1><a1>a1</a1>
<b1>a1</b1><b2>a2</b1>
<c1>a1</c1><c2>a2</c2>

It's not working with following sed command.

sed -n '/<Sample/,/<\/Sample/p' ab
Abhi S
  • 31
  • 1
  • 4