Cutting number from range in xml file

Hi folks,

I need to find the following value:
First,I need to find the starting section by finding the line:

<process-type id="OC4J_RiGHTv_${SCHEMA_NAME}" module-id="OC4J">

Second,under this line I need to find the following line:

<port id="rmi" range="3765-3776"/>

And third,from this line I need to cut the first number in the line. In this case it is 3765"

The section in the xml file looks as the following:

<process-type id="OC4J_RiGHTv_IAS10G" module-id="OC4J">
               <environment>
                  <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/>
                  <variable id="SHLIB_PATH" value="/home/ias/v10.1.2/lib32" append="true"/>
               </environment>
               <module-data>
                  <category id="start-parameters">
                     <data id="java-options" value="-server -Djava.security.policy=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IAS10G/config/java2.policy -Djava.awt.headless=true -Drightv.root=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IAS10G -Xmx512M -Duser.timezone=GMT+03:00"/>
                     <data id="oc4j-options" value="-properties"/>
                  </category>
                  <category id="stop-parameters">
                     <data id="java-options" value="-Djava.security.policy=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IAS10G/config/java2.policy -Djava.awt.headless=true -Drightv.root=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IAS10G -Xmx512M -Duser.timezone=GMT+03:00"/>
                  </category>
               </module-data>
               <start timeout="900" retry="2"/>
               <stop timeout="120"/>
               <restart timeout="720" retry="2"/>
               <port id="ajp" range="3301-3400"/>
               <port id="rmi" range="3765-3776"/>
               <port id="jms" range="3295-3296"/>
               <process-set id="default_island" numprocs="1"/>
            </process-type

>

$SCHEMA_NAME=IAS10G
How can I assign the first number in the range of rmi ports (3765 in this section) into a parameter?

Thanks in advance,
Nir

Try this.

sed -n '/process-type id="'"OC4J_RiGHTv_${SCHEMA_NAME}"'"/,/<\/process-type>/{ s/<port id="rmi".*\([0-9]\{4\}\)-.*/\1/p }' input.xml

Vino

Hey vino !

It's amazing command!!
It works fantastic!
No doubt that you are a sed expert!

Thanks a lot!

Best regards,
Nir

Here are some sed tutorials/articles.

Help yourself.

http://www.unix.com/showthread.php?t=13774
http://www.student.northpark.edu/pemente/sed/sed1line.txt

Vino

Thanks again vino!
It will be very helpfull.

Nir