Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using AWK to pull multiple values 1

Status
Not open for further replies.

cmarchman

Programmer
Jun 18, 2004
56
US
I've had some help with this in the past and it has proven to be of great aid to me, so any pointers in the right direction will be very appreciated.

I've got an XML file that contains various 'tagged' entities and I would like to separate those entities into fields.

example - <Host>xxx.xxx.xxx.xxx</Host><Port>80</Port><Issues><Issue>........(several other tags)<VulnerabilityID>XXX</VulnerabilityID><Name>..etc</Issue><Issue>....</Issue></Issues>.....

The problem is that the 'Host' info may contain numerous 'Issues' delimited by an 'Issue' tag. I'm looking to place appropriate tagged info into fields/records and print to a file for review. Dressing it up is no problem, just getting the initial info pulled out is the issue.

Thanks,

cmarchman
 
Side note:

Normally, I would just parse all this out to a MySQL db and write PERL to extrapulate from there. The client is not allowing that.

cmarchman
 
Judicious use of sed might work:

[tt]sed '
s#</[^>]*>##g
s#<\([^>]*\)>#\
\1: #g
s#Host:#\
Host:#
' /your/xml/file[/tt]

First part strips out the termination tags.
Second part puts each tag on a new line and strips off the <>.
Third part adds an extra new line between each host.

Annihilannic.
 
Annihilannic,

I like your approach on this. One of the main problems I was having is that the tags ran together as one huge line until some break was introduced within the <Summary> area, and sometimes not even then. This will help in the analysis of the data in a big way.

Thanks,

cmarchman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top