Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    India
    Posts
    41

    Unanswered: 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 15:25.

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    I assume \name should be /name
    Code:
    sed 's~\(.*\)\(<name>\)\(.*\)\(</name>\)\(.*\)~\2\3\4~' xmlfile

  3. #3
    Join Date
    Mar 2004
    Location
    India
    Posts
    41
    Thanks for the help! it works for me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •