Complicated string searching in a file

Hi folks,

Following a part of opmn.xml file:

            <process-type id="OC4J_RiGHTv_PLATOR81" 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_PLATOR81/config/java2.policy -Djava.awt.headless=true -Drightv.root=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_PLATOR81 -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_PLATOR81/config/java2.policy -Djava.awt.headless=true -Drightv.root=/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_PLATOR81 -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="4021-4032"/>
               <port id="jms" range="3821-3822"/>
               <process-set id="default_island" numprocs="1"/>
            </process-type>

This section appears a lot of times in this file. The uniqueness key is the schema name. In this example,the schema name is PLATOR81.
I need to find what is the first number in the line :
<port id="jms" range="3821-3822"/>
In this example : 3821

The steps suppose to be:

  1. Find the line : <process-type id="OC4J_RiGHTv_PLATOR81"
  2. Under this line ,find the line : <port id="jms" range="3821-3822"/>
  3. Cut the first number after "range="

Is there a way to do it in one command?

Thanks in advance,
Nir

  1. Cut the first number after "range="

Cut ? What do you mean ? Retrieve the first number only or remove that number from the line ?

vino

Looks very similiar to another post of yours Cutting number from range in xml file

Change the rmi to jms in the sed solution.

vino

Hi vino,

How are you?

In this thread I need something different than my former thread.
I need to retrieve the first number only after "range=" in this file section.
Last time I needed to replace the values in the section and you gave me a beautiful "sed" command.
Now I need to retrieve a value.

Thanks again!

Nir

Without re-inventing the wheel again, here is the solution

sed -n '/process-type id="'"OC4J_RiGHTv_PLATOR81"'"/,/<\/process-type>/{ s/<port id="jms".*\([0-9]\{4\}\)-.*/\1/p }' nir.xml

vino

It seems that you invented the wheel of sed ....
As always,your solutions are amazing!

Thanks a lot my friend!!

Best regards,
Nir