![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
|||||
|
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 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
ENV_FILE contains Code:
<environment>
<prop name=\"LD_LIBRARY_PATH\" value=\"${ORACLE_HOME}/lib\"/>
<prop name=\"SHLIB_PATH\" value=\"${ORACLE_HOME}/lib32\"/>
</environment>
|
|
||||
|
Hi vino,
I ran the following command: Code:
sed '/process-type id="'"$SCHEMA_NAME"'"/,/<\/process-type>/{ /<port id="jms".*/r foo.lst; }' opmn.xml
sed: -e expression #1, char 0: Unmatched `{' opmn.xml=inputfile foo.lst=ENV_FILE Thanks in advance, Nir |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|