start searching a word from the particular record on the result of first occurence change the value

Hi,
I need a script to start searching a word from the particular record on the result of first occurence i need to change the value in that record.

I have a input file like this

<properties> 
<add key="DeliveryWithinDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="0" /> 
</properties> 
<properties> 
<add key="ContactAddress" value="Home" /> 
<add key="AttemptInterval" value="10" /> 
<add key="Restarts" value="1000" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="RestartInterval" value="600" /> 
</properties> 
<properties> 
<add key="DeliveryNextDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="50" /> 
<add key="XAB" value="2" /> 
</properties> 
 

I would like to search a word "ContactAddress"(its unique value in a file) from here onwards i want to search a word "Restarts"(multiple occurences in a file) on the first occurence of result(<add key="Restarts" value="1000" /> ) in that i want to change the value 1000 to 500).

Expected output will be

<properties> 
<add key="DeliveryWithinDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="0" /> 
</properties> 
<properties> 
<add key="ContactAddress" value="Home" /> 
<add key="AttemptInterval" value="10" /> 
<add key="Restarts" value="500" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="RestartInterval" value="600" /> 
</properties> 
<properties> 
<add key="DeliveryNextDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="50" /> 
<add key="XAB" value="2" /> 
</properties> 
 

Thanks in advance

sed '/ContactAddress/,/Restarts/{
/Restarts/s/[0-9][0-9]*/500/
}' file

elixir,
Thanks for your quick reply.

value column may be a string also. how can i achieve this.

And one more thing, the search value(1000 or some string) and replace value(500 or a string) should be pass at runtime

string=1000
repl=500
sed '/ContactAddress/,/Restarts/{
/Restarts/s/value="'"$string"'"/value="'"$repl"'"/
}' file

elixir,

Thank you so much its working.
Could you please explain the command for my understanding

sed '/ContactAddress/,/Restarts/{
/Restarts/s/[0-9][0-9]*/500/
}' file
 

Is it possible to replace from its original file without redirecting to temporary file and again moving to original file.
I want to execute this as a command and not through the script

This expression is specifying a range of addresses to work upon and will select all blocks of lines containg "ContactAddress" in first line and "Restarts" in the last line. Since you mentioned that "ContactAddress" occurs only once in the file, only 1 such block is possible to be addressed by this expression.

In that selected block, in the last line (having the word "Restarts" which is the first occurrence of that word after "ContactAddress"), substitute a string of 1 or more digits with 500.

Check if your sed version supports in-place editing with the -i option.