XML file modifications using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML file modifications using sed
# 1  
Old 05-27-2009
XML file modifications using sed

Hi,

During an installation process in a bash script I need to do 2 things with 2 XML files. Does the use of sed affect in any way the XML file ?

1.Add to a section in <ServerListeners> section

<ServerListener>
<BaseClass>myapp.module.WowConfigurator</BaseClass>
</ServerListener>

The below code does the job, but it doesn;t format the xml file by adding tabs and all. Is that ok from an XML file point of view?

Code:
ISLISTENER=`grep -n "myapp" $WOW_HOME/conf/Server.xml|cut -d":" -f1 |head -1`

if [ ${ISLISTENER} == "" ]
then
        INSERTLINE=`grep -n "ServerListeners" $WOW_HOME/conf/Server.xml|cut -d":" -f1 |head -1`

        sed -e ''${INSERTLINE}'a\</ServerListener>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

        sed -e ''${INSERTLINE}'a\<BaseClass>myapp.module.WowConfigurator</BaseClass>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

        sed -e ''${INSERTLINE}'a\<ServerListener>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

fi


2. With a sed command I need to replace the value of a first occurrence of a parameter:

The xml file contains:
Code:
                                <IpAddress>*</IpAddress>
                                <Port>1935</Port>

And I need to replace with $BINDADDRESS and $BINDPORT variables. This I didn't manage to figure it out.

Thanks,
Bianca

Last edited by potro; 05-27-2009 at 11:41 AM..
# 2  
Old 05-27-2009
You are can use any editor, including sed, on an XML document. There is no requirement to use a specific editor.

In general white space does not matter in an XML document so long as it is well-formed and valid. Basically, a document is well-formed if it follows the syntax rules of the XML specification and the elements within it are correctly nested and part of a unique root.
# 3  
Old 05-27-2009
Hi,

The modification is done during the installation process from a bash script, this is why I cannot use an editor.

For the second issue I read 2 variables from user input and I need to replace the value in the XML file.

Thanks,
Bianca

Quote:
Originally Posted by fpmurphy
You are can use any editor, including sed, on an XML document. There is no requirement to use a specific editor.

In general white space does not matter in an XML document so long as it is well-formed and valid. Basically, a document is well-formed if it follows the syntax rules of the XML specification and the elements within it are correctly nested and part of a unique root.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed xml file script help

I have about 1200 xml files I need to deploy from a 6.4 XML version to 9.0 version of a DTD. So I need a sed command to do lots of of replacements of random variables. The keyword line is <AUTOEDIT EXP then is will have a variable followed by an equals sign. From that point on I need to break... (5 Replies)
Discussion started by: J-Man
5 Replies

2. Shell Programming and Scripting

Modifications using Lookup file

I have 2 files. File 1 delimited by ";" File 1: 001;0;11223;xx;N;1001051;124;1;1;1001051;110;0;A_15;D;DX;U 001;0;8830943;xx;P;1226040;978;1;0;1226040;110;0;A_15;D;DX;H 001;0;10946903;xx;N;1300496;978;1;1;1300496;110;0;A_17;D;DX;H... (2 Replies)
Discussion started by: pparthiv
2 Replies

3. Shell Programming and Scripting

Modifications to a file

I have a file whose format is shown below. It has a table of numbers. In this case, I have 16 values in 12 rows. I want to select a position in the table, example, the 5th number at row 5. I need to change the value in that position by a certain amount and output the file with the modifiation. ... (6 Replies)
Discussion started by: kristinu
6 Replies

4. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

5. Shell Programming and Scripting

Modifications to a file

Hi, I do not have a clue how to do this nor can I find information on it but I have a file that looks like this (basically 3 columns and tab delimited). I need this in a particular format in order for a program to actually read it. chr1 2 4 chr1 2 5 chr1 3 6 chr2 1 4 chr2 2 5 ... (2 Replies)
Discussion started by: kylle345
2 Replies

6. UNIX for Advanced & Expert Users

Parsing xml file using Sed

Hi All, I have this(.xml) file as: <!-- define your instance here --> <instance name='ins_C2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' > <property> </property> </instance> I want output as: <!-- define your instance here --> <instance... (3 Replies)
Discussion started by: kapilkinha
3 Replies

7. Shell Programming and Scripting

my shell script (file modifications)

hi guys Need some help on my below script #!/bin/sh if then echo "~~:S:wait:/sbin/sulogin" >> /root/joy/inittab else echo "/root/joy/inittab does not exist" fi now the problem is that when i run the above script it runs successfully but when i run it repeatedly the word echo... (2 Replies)
Discussion started by: whizkidash
2 Replies

8. Shell Programming and Scripting

extracting XML file using sed

Hello folks I want to extract data between certain tag in XML file using 'sed' <xml> ......... .......... <one>XXXXXXXXXXXXXXXXXXXX</one> ...... Anyone ?Thank you (7 Replies)
Discussion started by: pujansrt
7 Replies

9. UNIX for Advanced & Expert Users

Tracing file modifications

Hello all! Is there a way or a utility to trace any kind of file changes in a particular directory on any UNIX machine? The purpose is that in Unix, there are multiple ways of opening and making changes to a file. But internally, there must be something common (a single pipe, etc.) that is... (3 Replies)
Discussion started by: gupta_ca
3 Replies

10. Shell Programming and Scripting

In Line File Modifications: Search and Replace

grep -il "TEST" ${ENVIRON}/*.pde| while read pde &nbsp;&nbsp;do &nbsp;&nbsp;&nbsp;&nbsp;cat $pde | sed s/"TEST 3,1"/"TEST 3,0"/g | sed s/"TEST&nbsp;&nbsp;3,1"/"TEST&nbsp;&nbsp;3,0"/g > ${pde}.tmp &nbsp;&nbsp;&nbsp;&nbsp;if ; then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mv ${pde}.tmp $pde ... (2 Replies)
Discussion started by: Shakey21
2 Replies
Login or Register to Ask a Question