Unix Shell - Shell Script Parsing an XML File on Sun OS 5.5.1

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > Shell Script Parsing an XML File on Sun OS 5.5.1





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Shell Script Parsing an XML File on Sun OS 5.5.1
oozzzii

2006-01-30, 5:56 pm

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.

William Park

2006-01-30, 5:56 pm

oozzzii <osminm@gmail.com> wrote:
> 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

--
William Park <opengeometry@yahoo.ca>, Toronto, Canada
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/
oozzzii

2006-01-30, 5:56 pm

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.

Ed Morton

2006-01-30, 5:56 pm

oozzzii wrote:

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

2006-01-31, 2:48 am

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!

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com