The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-21-2005
Registered User
 

Join Date: Jun 2004
Posts: 146
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>
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
Reply With Quote
Forum Sponsor
  #2  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
Reply With Quote
  #3  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
Reply With Quote
  #4  
Old 09-21-2005
Registered User
 

Join Date: Jun 2004
Posts: 146
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
Reply With Quote
  #5  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
vino
Reply With Quote
  #6  
Old 09-21-2005
Registered User
 

Join Date: Jun 2004
Posts: 146
It seems that you invented the wheel of sed ....
As always,your solutions are amazing!

Thanks a lot my friend!!

Best regards,
Nir
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0