The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 03:39 PM
awk and file parsing devtakh Shell Programming and Scripting 4 05-06-2008 11:13 AM
Parsing a csv file chiru_h Shell Programming and Scripting 6 02-12-2008 09:33 AM
File Parsing jsusheel Shell Programming and Scripting 5 09-25-2007 10:25 AM
parsing file through awk bbeugie Shell Programming and Scripting 13 08-22-2006 01: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 04-08-2008
kapilkinha kapilkinha is offline
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 04:39 AM.. Reason: added code tags
  #2 (permalink)  
Old 04-08-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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
  #3 (permalink)  
Old 04-08-2008
kapilkinha kapilkinha is offline
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!!!!
  #4 (permalink)  
Old 04-08-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Try add another -e after the first -n. I think it requires one for each script snippet, if you have several.
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 12:40 AM.


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