Shell Script Parsing an XML File on Sun OS 5.5.1

Shell Script Parsing an XML File on Sun OS 5.5.1

Post by oozzzi » Wed, 01 Feb 2006 06:58:11



Hell everyone,

I read through similar postings before asking for help...I am limited
to the tools available from the Sun OS 5.5.1 install, e.g. no perl or
GNU awk, etc. I need to monitor the following xml file so data mame
always has a server name and the value of 0 or 1. But I can't seem to
find a way to delimit the values ..example, xml2 file:

    <type name="PING">
        <data name="server1">0</data>
    </type>
    <type name="NFS">
        <data name="server1">0</data>
    </type>

This is the closest that I've gotten but using awk:
awk 'BEGIN{FS="<[A-z]+[ \t][A-z]>|</[A-z]+>"}/data name/ {print $2}'
~/xml2

I'll appreciate any suggestions.

 
 
 

Shell Script Parsing an XML File on Sun OS 5.5.1

Post by William Par » Wed, 01 Feb 2006 07:36:00



> Hell everyone,

> I read through similar postings before asking for help...I am limited
> to the tools available from the Sun OS 5.5.1 install, e.g. no perl or
> GNU awk, etc. I need to monitor the following xml file so data mame
> always has a server name and the value of 0 or 1. But I can't seem to
> find a way to delimit the values ..example, xml2 file:

>     <type name="PING">
>         <data name="server1">0</data>
>     </type>
>     <type name="NFS">
>         <data name="server1">0</data>
>     </type>

> This is the closest that I've gotten but using awk:
> awk 'BEGIN{FS="<[A-z]+[ \t][A-z]>|</[A-z]+>"}/data name/ {print $2}'
> ~/xml2

> I'll appreciate any suggestions.

Can you compile Bash shell?  Because there is shell interface to Expat
XML parser, ie.
    http://home.eol.ca/~parkw/index.html#expat

--

ThinFlash: Linux thin-client on USB key (flash) drive
           http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
          http://freshmeat.net/projects/bashdiff/

 
 
 

Shell Script Parsing an XML File on Sun OS 5.5.1

Post by oozzzi » Wed, 01 Feb 2006 07:46:26


I am aware of many other tools that could do this with minor difficulty
but unfortunately adding those tools to the sytem is not an option...I
don't own administration on them.
 
 
 

Shell Script Parsing an XML File on Sun OS 5.5.1

Post by Ed Morto » Wed, 01 Feb 2006 08:09:35



> Hell everyone,

> I read through similar postings before asking for help...I am limited
> to the tools available from the Sun OS 5.5.1 install, e.g. no perl or
> GNU awk, etc. I need to monitor the following xml file so data mame
> always has a server name and the value of 0 or 1. But I can't seem to
> find a way to delimit the values ..example, xml2 file:

>     <type name="PING">
>         <data name="server1">0</data>
>     </type>
>     <type name="NFS">
>         <data name="server1">0</data>
>     </type>

> This is the closest that I've gotten but using awk:
> awk 'BEGIN{FS="<[A-z]+[ \t][A-z]>|</[A-z]+>"}/data name/ {print $2}'
> ~/xml2

> I'll appreciate any suggestions.

Which awk are you using? Solaris typically has a choice of 3 or 4:

    /usr/bin/awk (sometimes also available as /usr/bin/oawk)
    /usr/xpg4/bin/awk
    nawk

Do not use the first one listed ("old, broken awk"). The following
should work with either of the other 2.

If you just want to isolate "server1" and "0" from your above sample
input, this will isolate and print them as $2 and $3 respectively:

    awk -F'[<\"][^>\"]*[>\"]' '/data name/{print $2, $3}' ~/xml2

Without knowing what else can be in your file, it's hard to tell if
that's good enough for your needs.

Regards,

        Ed.

 
 
 

Shell Script Parsing an XML File on Sun OS 5.5.1

Post by oozzzi » Wed, 01 Feb 2006 13:51:50


Ed, I was using the first one and wasn't getting very far...the line
you provided works PERFECTLY for both nawk & /usr/xpg4/bin/awk.

Thank you for the help!

 
 
 

1. Parse an XML File using Shell script

Hello,

Could someone help me in this regard?

I have an Input file having more than 1000 entries as below in xml
format:

<UserData id="id10">
<UserValue value="1wCBEW9yBJSOzC" title="__TEST "></UserValue>
<UserValue value="1L2T-5K762-B" title="__ITEM_ID"></UserValue>
<UserValue value="11" title="__REVISION_ID"></UserValue>
<UserValue value="WIRING ASSEMBLY" title="__NAME"></UserValue>
<UserValue value="HUB" title="Exported To"></UserValue>
<UserValue value="1L2T-5K762-B" title="Item ID"></UserValue>
<UserValue value="11" title="Item Revision"></UserValue>
<UserValue value="Own" title="Owning Site"></UserValue>
<UserValue value="Pub" title="Release"></UserValue></Part>
<Part id="id17" instanceRefs="id27 id35" name="1L2T ASSEMBLY-4 PIN TR
(view)">

I would like to have the Output file in the following format for all
the entries as shown below:

Item ID       Item Revision     Owning Site    Release
1L2T-5K762-B      11              Own           Pun

Any help is highly appreciated.

Thanks, Karthik

2. Is ext3 file system safe? Still experimental?

3. Shell Scripts read and parse lines from a file

4. Maestro 16/96 / isapnp / module

5. INI files: is there a ksh shell script to parse them (like iniconf)?

6. Solaris 2.6

7. Shell script to parse a file

8. Connection without internet

9. parsing a line from file using shell scripts

10. Shell script to parse a log file

11. Copy files using filenames from text files with shell script or bash script

12. NEEDED: ms-window file viewer for sun solrais or sun os

13. Shell Script for parsing