The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Appending line ending with '}" to new line aismann Shell Programming and Scripting 4 08-13-2007 02:09 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-21-2007 01:29 AM
need help appending lines/combining lines within a file... mr_manny Shell Programming and Scripting 2 01-06-2006 06:45 PM
Appending Consecutive lines pondlife Shell Programming and Scripting 8 08-13-2004 05:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Appending line/lines with sed

Hi folks,

I need to append line or bulk of lines into a file.
For example,I have the following section in opmn.xml file:
<process-type id="OC4J_RTEadmin_NIR" module-id="OC4J">
<module-data>
<category id="start-parameters">
<data id="java-options" value="-server -Djava.security.policy=/home/ias/v10.1.2/j2ee/OC4J_RTEadmin_NIR/config/java2.policy -Djava.awt.headless=true"/>
<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_RTEadmin_NIR/config/java2.policy -Djava.awt.headless=true"/>
</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="3201-3300"/>
<port id="jms" range="3701-3800"/>
<process-set id="default_island" numprocs="1"/>
</process-type>

I need to do the following:
1. Locating the line number of the string : id="OC4J_RTEadmin_$SCHEMA_NAME" (no problem with me).
2. Under this string ,finding the line number of the string <port id="jms" range="3701-3800"/> (no problem with me).
3. After the line number from paragraph 2 ,inserting the following lines:
<environment>
<prop name=\"LD_LIBRARY_PATH\" value=\"${ORACLE_HOME}/lib\"/>
<prop name=\"SHLIB_PATH\" value=\"${ORACLE_HOME}/lib32\"/>
</environment>

Is it possible to do it with sed command?

Thanks in advance,
Nir
  #2 (permalink)  
Old 07-20-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
It would be better if you could put the input within the code tags for better readability.

The way sed is used in this case is,

Code:
sed '/search_string/r FILE' inputfile
where FILE has the contents of the which needs to be inserted after you find, the search_string.

I am continuing on the solution provided the other day by r2007.

Code:
sed '/process-type id="'"$SCHEMA_NAME"'"/,/<\/process-type>/{ /<port id="jms".*/r ENV_FILE; }' inputfile
Not tested tho'.

ENV_FILE contains

Code:
<environment>
<prop name=\"LD_LIBRARY_PATH\" value=\"${ORACLE_HOME}/lib\"/>
<prop name=\"SHLIB_PATH\" value=\"${ORACLE_HOME}/lib32\"/>
</environment>
vino
  #3 (permalink)  
Old 07-20-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Hi vino,

Thanks a lot!
I'm at home now,so I'll test it tomorrow and let you know.

Bye for now,
Nir
  #4 (permalink)  
Old 07-21-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Hi vino,

I ran the following command:
Code:
sed '/process-type id="'"$SCHEMA_NAME"'"/,/<\/process-type>/{ /<port id="jms".*/r foo.lst; }' opmn.xml
and I got the following error:
sed: -e expression #1, char 0: Unmatched `{'

opmn.xml=inputfile
foo.lst=ENV_FILE

Thanks in advance,
Nir
  #5 (permalink)  
Old 07-21-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
sed -e '/process-type id="'"$SCHEMA_NAME"'"/,/<\/process-type>/p' 
-e '/<port id="jms".*/r foo.lst' opmn.xml
Vino
  #6 (permalink)  
Old 07-21-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Hi vino,

Thanks again.
The command runs now but it appends the lines in the wrong place.

The section looks now:
<process-type id="OC4J_RTEadmin_NIR" module-id="OC4J">
<module-data>
<category id="start-parameters">
<data id="java-options" value="-server -Djava.security.policy=/home/ias/v10.1.2/j2ee/OC4J_RTEadmin_NIR/config/java2.policy -Djava.awt.headless=true"/>
<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_RTEadmin_NIR/config/java2.policy -Djava.awt.headless=true"/>
</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="3201-3300"/>
<port id="jms" range="3701-3800"/>
<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>
<process-set id="default_island" numprocs="1"/>
</process-type>

The bulk was inserted after jms line.
I wanted to insert the lines right after the string :
process-type id="OC4J_RTEadmin_$SCHEMA_NAME"

It should be as the following:

<process-type id="OC4J_RTEadmin_NIR" 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_RTEadmin_NIR/config/java2.policy -Djava.awt.headless=true"/>
<data id="oc4j-options" value="-properties"/>
</category>
....................

Thanks in advance,
Nir
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0