The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help me with parsing this file eamani_sun Shell Programming and Scripting 2 05-16-2008 12:39 PM
awk and file parsing devtakh Shell Programming and Scripting 4 05-06-2008 08:13 AM
Parsing a csv file chiru_h Shell Programming and Scripting 6 02-12-2008 06:33 AM
File Parsing jsusheel Shell Programming and Scripting 5 09-25-2007 07:25 AM
parsing file through awk bbeugie Shell Programming and Scripting 13 08-22-2006 10:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-08-2008
Registered User
 

Join Date: Dec 2007
Posts: 2
Unhappy Parsing xml file using Sed

Hi All,

I have this(.xml) file as:
Code:
 <!-- define your instance here -->
   <instance name='ins_C2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' >
      <property>
      </property>
   </instance>
I want output as:
Code:
<!-- define your instance here -->
   <instance name='ins_B2Londondev' user='C2_dev' group='sports' fullname='B2%20-%20London%20(dev)' >
            <property>
      </property>
   </instance>
I want to do this using Sed command.Please help as this is vey urgent.

Thanks in advance

Last edited by Yogesh Sawant; 04-08-2008 at 01:39 AM. Reason: added code tags
Reply With Quote
Forum Sponsor
  #2  
Old 04-08-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Perhaps you could elaborate on your requirements. If all you need is to change name='ins_C2Londondev' to name='ins_B2Londondev', change user='' to user='C2_dev', change group='' to group='sports' regardless of context, then you don't really need any XML parsing. Oh, and if the new values somehow depend on the input, we can't guess what they need to be, so you need to explain that. On the other hand, if you need real XML parsing, sed is not the right tool.

Code:
sed -e "s/name='ins_C2Londondev'/name='ins_B2Londondev'/" \
    -e "s/user=''/user='C2_dev'/" -e "s/group=''/group='sports'/" file.xml
Reply With Quote
  #3  
Old 04-08-2008
Registered User
 

Join Date: Dec 2007
Posts: 2
First of all thx for your time.This is the complete .xml file:<name>B2 - London</name>
<description>Calculates risk numbers for the global SCT desk and london credit flow desk</description>
<version>1.0</version>
<revision></revision>
<revcomment></revcomment>
<bline>Fixed Income</bline>
<userid>kkinha</userid>

<!-- define your global properties here -->
<property>
<SRC_PATH>/home/B2_dev/grid/B2_RiskEngine_Grid/OvernightLondon/VB2.STABLE</SRC_PATH>
</property>

<!-- define your instance here -->
<instance name='ins_B2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' >
<!-- ins_B2Londondev = B2 - London (dev) -->
<!-- define your instance specific properties here -->
<property>
</property>
</instance>
<instance name='ins_B2Londonprod' user='' group='' fullname='B2%20-%20London%20(prod)' >
<!-- ins_B2Londonprod = B2 - London (prod) -->
<!-- define your instance specific properties here -->
<property>
</property>
</instance>
<instance name='ins_B2LondonInt' user='' group='' fullname='B2%20-%20London%20(Stage)' >
<!-- ins_B2LondonInt = B2 - London (Stage) -->
<!-- define your instance specific properties here -->
<property>
</property>
</instance>

<component name='Undefined'>
<version>1.0</version>

<os>Red Hat Enterprise Linux AS 4</os>

<os>SunOS 5.8</os>

<package>B2_GridComponentInstall</package>
</component>

<package name='B2_GridComponentInstall'>
<description>Package for deploying B2 - London</description>
<version>1.0</version>

<dir src='${SRC_PATH}' dst='/home/${user}' owner='${user}' group='${group}' type='' exclude='' perm='755' option='' />
<post>${SRC_PATH}/deployOvernightRiskEngine.bat</post>
<auto_home key='${user}' path='/local/0/home/${user}' server='localhost' />


</package>

</application>


I have to change user='' to user='C2_Dev' , group='' to group='sports' and dst='/home/${user} to dst=$DST_PATH.Where DST_PATH is shell script variable.User and group shd be changed depending on user input i.e instance name for ex. if instance name is ins_B2Londondev then user and group for that instance shd be changed.I am doin like this buts it's giving error:
sed -n \
"/${Instance}/p"\
-e '/instance name/p'\
-e "s/user=''/user='B2_dev'/" -e "s/group=''/group='games'/" B2GridTemplate.xml

Error::Can't open -e
Can't open /instance name/p
Can't open -e
Can't open s/user=''/user='B2_dev'/
Can't open -e
Can't open s/group=''/group='games'/
<instance name='ins_B2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' >
<!-- ins_B2Londondev = B2 - London (dev) -->

Please help!!!!
Reply With Quote
  #4  
Old 04-08-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Try add another -e after the first -n. I think it requires one for each script snippet, if you have several.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0