Need help in finding and replacing port numbers.

Hi All,

I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no.

let me clear it with an example-
suppose there r few files a,b,c,d....

file a's content-

<serverEntries xmi:id="ServerEntry_1" serverDisplayName="server1" serverName="server1" serverType="APPLICATION_SERVER">
<specialEndpoints xmi:id="NamedEndPoint_1" endPointName="BOOTSTRAP_ADDRESS">
<endPoint xmi:id="EndPoint_1" host="stlhp59.amdocs.com" port="9810"/>
</specialEndpoints>
<specialEndpoints xmi:id="NamedEndPoint_2" endPointName="SOAP_CONNECTOR_ADDRESS">
<endPoint xmi:id="EndPoint_2" host="stlhp59.amdocs.com" port="8880"/>

file b's content-

<transports xmi:type="applicationserver.webcontainer:HTTPTransport" xmi:id="HTTPTransport_1218229086147" external="false" sslEnabled="false" sslConfig=
"amssManagerPS2-stlhp59/DefaultSSLSettings">
<address xmi:id="EndPoint_1218229086147" host="" port="32203"/>
</transports>
<transports xmi:type="applicationserver.webcontainer:HTTPTransport" xmi:id="HTTPTransport_1218229103919" external="false" sslEnabled="true" sslConfig="
amssManagerPS2-stlhp59/DefaultSSLSettings">
<address xmi:id="EndPoint_1218229103919" host="
" port="32204"/>

there r few more files----

now i want to increase all the values of ports (only port and not transport n other port containing words) by 200.

can some one help.. how to get the above mentioned result

Assuming the same file format as above:

for file in files_list*
 do
  awk -F'"' '/port="[0-9]+"/{OFS=FS; $(NF-1)=$(NF-1)+200; print; next}1'   "$file" > "$file".new
 done

if you have Python

import os,glob,re,fileinput
pat=re.compile("port=\"(.*?)\"")
directory="/home/yhlee/test/"
for files in glob.glob(directory+"/file"):
    for lines in fileinput.FileInput(files,inplace=1):
        lines = lines.strip()
        if "EndPoint" in lines and pat.search(lines):
            port=int(pat.findall(lines)[0]) + 200
            print pat.sub("port=\""+str(port)+"\"",lines)            
        else:
            print lines

Thanks for the above posts but

The number of files are not fixed... also I need a shell script solution n not have python.

also ...the script can have perl commands in it.

Please help