Appending string to xml file using "sed"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending string to xml file using "sed"
# 1  
Old 05-08-2006
Appending string to xml file using "sed"

Hi folks,

Following a section in opmn.xml file:
Code:
</process-type>
    <process-type id="OC4J_RiGHTv_IRD1" 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>

I need to find the line <process-type id="OC4J_RiGHTv_<SCHEMA_NAME>
Under this line find the line "<variable id="LD_LIBRARY_PATH .........."
and appending under this line :
<variable id="LD_LIBRARY_PATH" value="${ORACLE_HOME}/j2ee/OC4J_RiGHTv_${SCHEMA_NAME}/orca-3rd-lib" append="true"/>

The requested result should be :
ORACLE_HOME=/home/ias/v10.1.2
SCHEMA_NAME=IRD1
Code:
</process-type>
    <process-type id="OC4J_RiGHTv_IRD1" module-id="OC4J">
        <environment>
            <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/>
            <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib" append="true"/>
            <variable id="SHLIB_PATH" value="/home/ias/v10.1.2/lib32" append="true"/>
        </environment>

I wrote the following function:
Code:
update_opmn_xml()
{
opmnXml=/tmp/opmn.xml
export SCHEMA_NAME=IRD1
export ORACLE_HOME=/home/ias/v10.1.2
echo "<variable id=\"LD_LIBRARY_PATH\" value=\"${ORACLE_HOME}/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib\" append=\"true\"/>" > /tmp/append_str.lst
sed -e '/process-type id="'"OC4J_RiGHTv_${SCHEMA_NAME}"'"/,/variable id=\"LD_LIBRARY_PATH\"/r /tmp/append_str.lst' ${opmnXml} > ${opmnXml}.new

mv ${opmnXml}.new ${opmnXml}
chown ias:oinstall ${opmnXml}
}

I run the function and the final result was not as I needed:
Code:
</process-type>
            <process-type id="OC4J_RiGHTv_IRD1" module-id="OC4J">
<variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib" append="true"/>
               <environment>
<variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib" append="true"/>
                  <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/>
<variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib" append="true"/>
                  <variable id="SHLIB_PATH" value="/home/ias/v10.1.2/lib32" append="true"/>
               </environment>

What is my mistake in the function update_opmn_xml?

Thanks in advance,
Nir
# 2  
Old 05-09-2006
Quote:
Originally Posted by nir_s
Code:
update_opmn_xml()
{
opmnXml=/tmp/opmn.xml
export SCHEMA_NAME=IRD1
export ORACLE_HOME=/home/ias/v10.1.2
echo "<variable id=\"LD_LIBRARY_PATH\" value=\"${ORACLE_HOME}/j2ee/OC4J_RiGHTv_IRD1/orca-3rd-lib\" append=\"true\"/>" > /tmp/append_str.lst
sed -e '/process-type id="'"OC4J_RiGHTv_${SCHEMA_NAME}"'"/,/variable id=\"LD_LIBRARY_PATH\"/r /tmp/append_str.lst' ${opmnXml} > ${opmnXml}.new

mv ${opmnXml}.new ${opmnXml}
chown ias:oinstall ${opmnXml}
}

The above becomes

Code:
sed -e '/variable id=\"LD_LIBRARY_PATH\"/r /tmp/append_str.lst' ${opmnXml} > ${opmnXml}.new

# 3  
Old 05-09-2006
Hey vino,

Thanks a lot for your reply!
It is close to what I need.
Let me clarify :
The string <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> appears a lot in opmn.xml so I cannot find this string and append bellow it my string.
The unique string is <process-type id="OC4J_RiGHTv_$SCHEMA_NAME" module-id="OC4J">

So ,the find steps for the sed should be:
1. Find <process-type id="OC4J_RiGHTv_$SCHEMA_NAME" module-id="OC4J">
2. Bellow the above ,find <variable id="LD_LIBRARY_PATH" value="$ORACLE_HOME/lib"
3. Under the string from step 2,append the requested string.

I hope I clarified my task.

Thanks in advance,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

Help to change the file with "sed" and "awk"

Hi experts I want your help to change the file format to my wanted version, please give me a hand thanks $cat file install pass make os pass make build kernel failed usb storage pass chane to | *install* | *make os* | *make build kernel* | *usb storage* | | pass | pass... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

9. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

10. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies
Login or Register to Ask a Question