Sponsored Content
Full Discussion: Parsing xml file using Sed
Top Forums UNIX for Advanced & Expert Users Parsing xml file using Sed Post 302183024 by kapilkinha on Tuesday 8th of April 2008 04:58:58 AM
Old 04-08-2008
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!!!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can i do XML parsing usind sed

Hi all... I want to parse a xml filein unix .. Can i use SED or unix script to parse the xml file .. If so can anyone show a sample script that will parse the xml file .. Thanks in advance, Arun ,,,, (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Shell Programming and Scripting

parsing xml with awk/sed

Hi people!, I need extract from the file (test-file.txt) the values between <context> and </context> tag's , the total are 7 lines,but i can only get 5 or 2 lines!!:confused: Please look my code: #awk '/context/{flag=1} /\/context/{flag=0} !/context/{ if (flag==1) p rint $0; }'... (3 Replies)
Discussion started by: ricgamch
3 Replies

3. UNIX for Dummies Questions & Answers

Help parsing a XML file ....

Well I have read several threads on the subject ... but being a newbie like me makes it hard to understand ... What I need is the following: Input data: ------- snip --------- <FavouriteLocations> <FavouriteLocations class="FavouriteList"><Item... (6 Replies)
Discussion started by: misak
6 Replies

4. Shell Programming and Scripting

Parsing xml file

hi guys, great help to the original question, can i expand please? i have large files filled with blocks like this <Placemark> network type: hot line1 line2 line3 <styleUrl>red.png</styleUrl> </Placemark> <Placemark> network type: cold line1 line2 line3... (3 Replies)
Discussion started by: garvald
3 Replies

5. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

parsing xml file

Hello! We need to parse weblogic config.xml file and display rows in format: machine:listen-port:name:application_name In our enviroment the output should be (one line for every instance): Crm-Test-Web:8001:PIA:peoplesoft Crm-Test-Web:8011:PIA:peoplesoft... (9 Replies)
Discussion started by: annar
9 Replies

7. Shell Programming and Scripting

Parsing an XML file

Hello, I have the following xml file as an input. <?xml version="1.0" encoding="UTF-8"?> <RECORDS PS3_VERSION="1104_01"><RECORD> <POI_ID>931</POI_ID> <SUPPLIER_ID>2</SUPPLIER_ID> <POI_PVID>997920846</POI_PVID> <DB_ID>1366650925</DB_ID> <REGION>H1</REGION> <POI_NAME NAME_TYPE="Official"... (4 Replies)
Discussion started by: ramky79
4 Replies

8. Shell Programming and Scripting

XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere. I can not supply any sample file as it contains private data but you can download your own contacts using this script: #!/bin/sh # imports... (9 Replies)
Discussion started by: ripat
9 Replies

9. UNIX for Dummies Questions & Answers

Parsing XML file

I want to parse xml file sample file....... <name locale="en">my_name<>/name><lastChanged>somedate</lastChanged><some more code here> <name locale="en">tablename1<>/name><lastChanged>somedate</lastChanged> <definition><dbquery><sources><sql type="cognos">select * from... (10 Replies)
Discussion started by: ms2001
10 Replies

10. Shell Programming and Scripting

Help with parsing xml file

Hi, Need help with parsing xml data in unix and place it in a csv file. My xml file looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <iwgroups> <nextid value="128"> </nextid> <iwgroup name="RXapproval" id="124" display-name="RXapproval"... (11 Replies)
Discussion started by: ajayakunuri
11 Replies
XML_PP(1p)						User Contributed Perl Documentation						XML_PP(1p)

NAME
xml_pp - xml pretty-printer SYNOPSYS
xml_pp [options] [<files>] DESCRIPTION
XML pretty printer using XML::Twig OPTIONS
-i[<extension>] edits the file(s) in place, if an extension is provided (no space between "-i" and the extension) then the original file is backed-up with that extension The rules for the extension are the same as Perl's (see perldoc perlrun): if the extension includes no "*" then it is appended to the original file name, If the extension does contain one or more "*" characters, then each "*" is replaced with the current filename. -s <style> the style to use for pretty printing: none, nsgmls, nice, indented, record, or record_c (see XML::Twig docs for the exact description of those styles), 'indented' by default -p <tag(s)> preserves white spaces in tags. You can use several "-p" options or quote the tags if you need more than one -e <encoding> use XML::Twig output_encoding (based on Text::Iconv or Unicode::Map8 and Unicode::String) to set the output encoding. By default the original encoding is preserved. If this option is used the XML declaration is updated (and created if there was none). Make sure that the encoding is supported by the parser you use if you want to be able to process the pretty_printed file (XML::Parser does not support 'latin1' for example, you have to use 'iso-8859-1') -l loads the documents in memory instead of outputing them as they are being parsed. This prevents a bug (see BUGS) but uses more memory -f <file> read the list of files to process from <file>, one per line -v verbose (list the current file being processed) -- stop argument processing (to process files that start with -) -h display help EXAMPLES
xml_pp foo.xml > foo_pp.xml # pretty print foo.xml xml_pp < foo.xml > foo_pp.xml # pretty print from standard input xml_pp -v -i.bak *.xml # pretty print .xml files, with backups xml_pp -v -i'orig_*' *.xml # backups are named orig_<filename> xml_pp -i -p pre foo.xhtml # preserve spaces in pre tags xml_pp -i.bak -p 'pre code' foo.xml # preserve spaces in pre and code tags xml_pp -i.bak -p pre -p code foo.xml # same xml_pp -i -s record mydb_export.xml # pretty print using the record style xml_pp -e utf8 -i foo.xml # output will be in utf8 xml_pp -e iso-8859-1 -i foo.xml # output will be in iso-8859-1 xml_pp -v -i.bak -f lof # pretty print in place files from lof xml_pp -- -i.xml # pretty print the -i.xml file xml_pp -l foo.xml # loads the entire file in memory # before pretty printing it xml_pp -h # display help BUGS
Elements with mixed content that start with an embedded element get an extra <elt><b>b</b>toto<b>bold</b></elt> will be output as <elt> <b>b</b>toto<b>bold</b></elt> Using the "-l" option solves this bug (but uses more memory) TODO
update XML::Twig to use Encode with perl 5.8.0 AUTHOR
Michel Rodriguez <mirod@xmltwig.com> perl v5.12.4 2011-05-18 XML_PP(1p)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy