find string nth occurrence in file and print line number

Hi

I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)

Data in File.

<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
</QUOTE>

I want to get the first occurrence of the <SESSION> and </SESSION> and process between lines.
Again capture data from 2nd occurrence of the <SESSION> and </SESSION> until last occurrence repeat the same.

Thanks for help.
Mallik.

Don't quite know what you mean by "process between lines" but this prints the lines:

sed -n '/<SESSION>/,/<\/SESSION>/p' infile

Thanks for your prompt response.

Is there any way to to split the output occurrence wise. I want to print first occurrence into file1 and 2nd occurrence into file2.

How about this, (produces 1.out, 2.out etc.)

sed -n '/<SESSION>/,/<\/SESSION>/p' infile | awk ' NF { print $0 RS > ++j ".out" } ' RS='</SESSION>'

This is really helpful.. But this is creating n+1 output files. If i have 2 occurrences of the </SESSION> string in a file but output files are 3.

---------- Post updated at 01:49 PM ---------- Previous update was at 01:23 PM ----------

Thanks for all your help Chubler_XL.

Can you help me to find solution to below requirement.

Now i want to get the data starts with <SESSION and containing SESSIONNAME='mappingname1' , mappingname1 value is dynamic.

Example of the SESSION value

<SESSION DESCRIPTION ="" ISVALID ="YES" NAME ="s_m_FF_OM_RA_TERMS_TL_REV"  SORTORDER ="Binary" VERSIONNUMBER ="1">
sed -n '/<SESSION>/,/<\/SESSION>/p' infile | awk ' NF { print $0 RS > ++j ".out" } ' RS='</SESSION>'

---------- Post updated 10-07-11 at 01:20 AM ---------- Previous update was 10-06-11 at 01:49 PM ----------

can anyone help me to get solution for above requirement.

Appreciate all your help..

sed -n '/<SESSION/,/<\/SESSION>/p' infile | awk ' NF { print $0 RS > ++j ".out" } ' RS='</SESSION>'

Thanks for solution.. But i was looking for.

line starts with '<SESSION ' and also contains 'NAME=' in same line anywhere as a first parameter. this will gives me exact session which i want and that combination is always unique.

I want to try some thing like below.

sed -n '/ <line starts with <SESSION and contains 'NAME=$sessionname'> /,/<\/SESSION>/p' infile | awk ' NF { print $0 RS > ++j ".out" } ' RS='</SESSION>'