![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PERL: Searching for a string in a text file problem | meevagh | Shell Programming and Scripting | 15 | 05-01-2008 07:57 AM |
| searching for a string in a file | ROOZ | UNIX for Dummies Questions & Answers | 2 | 03-07-2008 10:54 AM |
| Extracting a string from one file and searching the same string in other files | mohancrr | Shell Programming and Scripting | 1 | 09-19-2007 12:17 AM |
| Perl: searching for a string in a file... | pondlife | Shell Programming and Scripting | 4 | 09-17-2007 04:35 AM |
| searching for a string though file system | peter.herlihy | UNIX for Dummies Questions & Answers | 3 | 12-06-2001 01:19 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Complicated string searching in a file
Hi folks,
Following a part of opmn.xml file: Code:
<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>
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
3. Cut the first number after "range="
Cut ? What do you mean ? Retrieve the first number only or remove that number from the line ? vino |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
Without re-inventing the wheel again, here is the solution
Code:
sed -n '/process-type id="'"OC4J_RiGHTv_PLATOR81"'"/,/<\/process-type>/{ s/<port id="jms".*\([0-9]\{4\}\)-.*/\1/p }' nir.xml
|
|
#6
|
|||
|
|||
|
It seems that you invented the wheel of sed ....
As always,your solutions are amazing! Thanks a lot my friend!! Best regards, Nir |
|||
| Google The UNIX and Linux Forums |