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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to write modifications in to two tables naveeng.81 Shell Programming and Scripting 0 04-09-2008 02:26 PM
my shell script (file modifications) whizkidash Shell Programming and Scripting 2 03-24-2008 03:50 PM
list files with modifications <15 minutes tom_k_mishra UNIX for Dummies Questions & Answers 2 11-11-2005 02:10 AM
Tracing file modifications gupta_ca UNIX for Advanced & Expert Users 3 08-03-2005 09:50 AM
In Line File Modifications: Search and Replace Shakey21 Shell Programming and Scripting 2 11-20-2001 04:21 PM

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 05-27-2009
potro's Avatar
potro potro is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 61
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 (permalink)  
Old 05-27-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
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 (permalink)  
Old 05-27-2009
potro's Avatar
potro potro is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 61
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 View Post
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.
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 09:34 PM.


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