The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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..