Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Unanswered: Shell Script to read XML tags and the data within that tag

    Hi unix Gurus,

    I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information.

    For example
    <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME ="ACTRL_BNFT_KEY_DMN" OBJECTVERSION ="1" OWNERNAME ="COC_V20_ETL_APPL" VERSIONNUMBER ="1">
    <SOURCEFIELD BUSINESSNAME ="" DATATYPE ="varchar" DESCRIPTION ="" FIELDNUMBER ="1" FIELDPROPERTY ="0" FIELDTYPE ="ELEMITEM" HIDDEN ="NO" </SOURCE>

    From the above xml file , I have to read the xml file and get the source name from the file as the below output.

    SOURCE ->ACTRL_BNFT_KEY_DMN.

    Please help me UNIX Gurus.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    If you mean a ksh or bash script, then you really have to limit the amount of parsing you want to do.
    You could grep the xml file for the tag name, and hope that the entire start tag, data, and end tag appear on the same line.
    If you get consistent results with grep, then you need to parse the line either with sed, or read using an appropriate IFS (internal field separator) value.
    Probably the best solution would be to find an application program that will import xml files into a database, then export the database into a csv or fixed column file.

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

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