Parsing and getting data from XML file using ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing and getting data from XML file using ksh script
# 1  
Old 12-05-2007
Parsing and getting data from XML file using ksh script

Hi All,

I have a xml file for example as described below

<xml>
<address>
<street><street>
<address/>
<isbn>426728783932020308393930303</isbn>
<book>
<name>
</name>
</book>
.
.
.
</xml>

My problem is to get the isbn number from the above described file using ksh script. Could anybody help me in solving this issue?


Thanks,
Vinna
# 2  
Old 12-05-2007
Code:
sed -n -e "s/<isbn>\([0-9]*\)<\/isbn>/\1/p" file.xml


Last edited by vino; 12-06-2007 at 01:28 AM.. Reason: Typo
# 3  
Old 12-06-2007
Quote:
Originally Posted by vino
Code:
sed -n -e "s/<isbn>/([0-9]*/)<\/isbn>/\1/p" file.xml

shouldn't this be,

Code:
sed -n -e "s/<isbn>\([0-9]*\)<\/isbn>/\1/p" file.xml

# 4  
Old 12-06-2007
more better

Code:
sed -n -e "/<isbn>/s/<isbn>\([0-9]*\)<\/isbn>/\1/p" file.xml

# 5  
Old 12-06-2007
Quote:
Originally Posted by matrixmadhan
shouldn't this be,

Code:
sed -n -e "s/<isbn>\([0-9]*\)<\/isbn>/\1/p" file.xml

Yes and thanks.
# 6  
Old 12-06-2007
Script Help

In the above defined xml file, all the tag elements are defined in a single line. Then how to get isbn?

for example:

<xml><address><street><street><address/><isbn>426728783932020308393930303</isbn><book><name></name></book>...</xml>

Thanks,
Vinna
# 7  
Old 12-08-2007
Code:
echo "<xml><address><street><street><address/><isbn>426728783932020308393930303</isbn><book><name></name></book>...</xml>" | sed -n 's/^.*<isbn>\([0-9]*\)<\/isbn>.*$/\1/p'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing custom data into xml in Shell

Hi , I have data as below in a text file { 'AAA' => { 'A1' => 'a1 comment', 'A2' => 'a2 comment' }, 'BBB' => { 'B1' => 'b1 comment' }, 'CCC' => { 'C1' => 'c1 comment', 'C2' => 'c2 comment', 'C3' => 'c3 comment' 'C4' => 'c4... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

3. 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

4. Shell Programming and Scripting

Help - Parsing data in XML in Linux

Hi, I have an XML file in Linux and it contains a long string of characters. The last part of the file is like ....... ....... ....... CAD</MarketDescription></InvestorTransaction></AdvisorAccount></DivisionAdvisor></Division>... (3 Replies)
Discussion started by: naveed
3 Replies

5. Shell Programming and Scripting

XML parsing in KSH

Hi All, Although I was able to find past XML parsing questions, as the questions were a little different than this, I had a pretty hard time adapting those answers to this scenario. -> May I ask if anyone knows how to extract the IP addresses of the below "servers.xml" file into an array... (5 Replies)
Discussion started by: chatguy
5 Replies

6. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

7. Shell Programming and Scripting

Parsing posted XML data from a remote server?

Hi Is it possible to parse a posted xml data from a remote server in unix shell script. if so how to do that? and i need to give this script path in the push url (in remote server) . how to do this? I have tried this in asp but could not succeed....so am trying in shell scripting...the thread... (1 Reply)
Discussion started by: aemunathan
1 Replies

8. Shell Programming and Scripting

XML file parsing using script

Hi I need some help with XML file parsing. I have an XML file with the below tag, I need a script to identify the value of srvcName which is this case is "AAA srvc name". I need to put contents of this value which is AAA srvc and name into different variables using an array and then reformat it... (6 Replies)
Discussion started by: zmfcat1
6 Replies

9. Shell Programming and Scripting

KSH Script to Get the <TAG Values> from an XML file

Hi All, I am new to Unix I need a KSH script to get the values from XML file to write to a temp file. Like the requirement is from the below TAG <MAPPING DESCRIPTION ="Test Mapping" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"> I need the MAPPING DESCRIPTION... (3 Replies)
Discussion started by: perlamohan
3 Replies

10. UNIX for Dummies Questions & Answers

Parsing XML dynamic data via awk?

I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now: echo -n "Running... (5 Replies)
Discussion started by: corwin43
5 Replies
Login or Register to Ask a Question