Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30

    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

    Code:
                    <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

  2. #2
    Just Joined!
    Join Date
    Mar 2008
    Posts
    30
    Hi,

    Fixed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •