If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Extracting a particular data.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-08, 13:55
arunprasadlv arunprasadlv is offline
Registered User
 
Join Date: Mar 2004
Location: India
Posts: 41
Extracting a particular data.

Hi,

I have a xml file and want to extract a particular data from the xml.
Is there any way in unix to extract a particular tag.

<start><name>123<\name><addr>BAC<\addr><loc>sfo<\l oc></start>
<start><addr>ABC<\addr><name>456<\name><loc>clt<\l oc></start>
<start><addr>DSC<\addr><loc>ram<\loc><name>789<\na me></start>
<start><name>1012<\name><addr>ERF<\addr><loc>nyc<\ loc></start>

In the above example , i want to extract all the fields starting with <name>???</name>.

Expected o/p:

<name>123<\name>
<name>456<\name>
<name>789<\name>
<name>1012<\name>


Thanks,
Arun

Last edited by arunprasadlv; 02-18-08 at 14:25.
Reply With Quote
  #2 (permalink)  
Old 02-19-08, 01:52
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
I assume \name should be /name
Code:
sed 's~\(.*\)\(<name>\)\(.*\)\(</name>\)\(.*\)~\2\3\4~' xmlfile
Reply With Quote
  #3 (permalink)  
Old 02-19-08, 13:31
arunprasadlv arunprasadlv is offline
Registered User
 
Join Date: Mar 2004
Location: India
Posts: 41
Thanks for the help! it works for me
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On