Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like:
<ROW>
some information
more information
</ROW>
I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?

thanks, jbruce

I don't know how your file is formatted but you can give this a try:

awk '/<pattern>/{gsub("\n$|^\n","");print}' RS="<ROW>|</ROW>" file

Hi, just a quick note about RS, this does not work in every awk, from the POSIX specification:

awk:Variables and Special Variables

@Scrutinizer, thanks for mention that :b:, an adapted version:

awk '/<pattern>/{gsub("\n$|^\n|ROW>\n","");print}' RS="<" file

Best regards

Franklin,
file format is
<ROW>
<OBJECT_ID>32948</OBJECT_ID>
<OBJECT_SEQ_NO>1</OBJECT_SEQ_NO>
<OBJECT_DATA> as much as 24 lines X 80 characters </OBJECT_DATA>
</ROW>

OR

<ROW>
<OBJECT_ID>32948</OBJECT_ID>
<OBJECT_SEQ_NO>2</OBJECT_SEQ_NO>
<OBJECT_DATA> or just a single line /OBJECT_DATA>
</ROW>
this could be repeated a thousand times, of course with different information between the <ROW> and </ROW>. I did try your suggestion and got this output:
awk: Line OBJECT_DATA>NAU-AKL- cannot have more than 199 fields.
The input line number is 33. The file is ORACLE_OBJECT_001.xml.good.
The source line number is 1.

Try this approach:

awk '
/<\/ROW>/ && b {print s; exit}
/<ROW>/{s="";next}
/<pattern>/{b=1}
{s=s?s RS $0:$0}' file

Franklin, Thank you for the time you have taken to answer my query. The latest code works and produces the output that I wanted, however it will stop at the first occurrence of the <pattern>. In the file I am using for my test there are 19 of the key words.

To print all the sections with the key word you can use this:

awk '
/<\/ROW>/ && b {print s; b=0}
/<ROW>/{s="";next}
/<key word>/{b=1}
{s=s?s RS $0:$0}' file