How to replace a line below where the pattern found

Hi All,

I have a file say abc.xml. In this file, I need to search for a pattern �SAP_GATEWAY_HOST�; if this pattern found and the next line also contain the pattern �nwprc03.cos� then I need to replace this pattern �nwprc03.cos� with some other pattern �nwdrc03.apjp�.

$ cat abc.xml
<NameValuePair>
<name>SAP_APPLICATION_HOST</name>
<value>nwprc00.cos</value>
</NameValuePair>
<NameValuePair>
<name>SAP_GATEWAY_HOST</name>
<value>nwprc00.cos</value>
</NameValuePair>

Required abc.xml should be:
$ cat abc.xml
<NameValuePair>
<name>SAP_APPLICATION_HOST</name>
<value>nwprc00.cos</value>
</NameValuePair>
<NameValuePair>
<NameValuePair>
<name>SAP_GATEWAY_HOST</name>
<value>nwdrc01.apjp</value>
</NameValuePair>

Thanks,
Ritesh Jain

this should work:

#  awk '!/SAP_GATEWAY_HOST/{print}      /SAP_GATEWAY_HOST/{print;getline; gsub(/nwprc00.cos/,"nwdrc03.apjp",$0);print}' abc.xml


<NameValuePair>
<name>SAP_APPLICATION_HOST</name>
<value>nwprc00.cos</value>
</NameValuePair>
<NameValuePair>
<name>SAP_GATEWAY_HOST</name>
<value>nwdrc03.apjp</value>
</NameValuePair>

(use nawk or /usr/xpg4/bin/awk for Solaris)

Another one:

awk '/SAP_APPLICATION_HOST/{f=0}/nwprc00.cos/{if(!f){f++}else{gsub(/nwprc00.cos/,"nwdrc03.apjp",$0)}}1' file

Thanks Tytalus & Danmero for your valueable suggession.