The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl parsing compared to Ksh parsing popeye Shell Programming and Scripting 1 08-06-2008 11:46 PM
XML Log Parsing pk_eee Shell Programming and Scripting 3 07-25-2008 01:18 PM
awk sed parsing Darsh Shell Programming and Scripting 3 03-12-2008 12:31 PM
parsing tungaw2004 UNIX for Dummies Questions & Answers 15 03-27-2007 09:33 PM
parsing xml walnut Shell Programming and Scripting 1 02-21-2006 05:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-16-2008
Mavericc Mavericc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 5
Thumbs up XML Parsing

Hi,

Need a script to parse the following xml file content

<tag1 Name="val1">
<abc Name="key"/>
<abc Name="pass">*********</abc>
</tag1>
<tag2 Name="Core">
<Host Name="a.b.c">
<tag1 Name="abc">
<abc Name="ac">None</abc>
<abc Name="as">None</abc>
<tag1 Name="pkg">
<tag1 Name="one">
<tag1 Name="two">
<abc Name="Version">1.3</abc >
<abc Name="Status">installed</abc >
<abc Name="InstalledName">two</abc >
</tag1 >
</tag1 >
</tag1 >
<abc Name="SystemType">SunOS</abc >
</tag1 >
</Host>
</tag2>


I can have multiple entries of Host tag so i need to search for a host with a given value and then get the attribute "ac" for a tag "abc" for the given Host

Thanks in advance.

Mavericc
  #2 (permalink)  
Old 09-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Try this:


Code:
awk -F '[<>]+' '
        /Host Name="a.b.c"/ { found=1 }
        found && /Name="ac"/ { print $3; found=0 }
' inputfile

  #3 (permalink)  
Old 09-16-2008
Mavericc Mavericc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 5
Works..but need more

Thanks...

It works if the "a.b.c" is hardcoded. How to go about if I were to pass it as argument.

Tried storing it in a variable and passed. But fails

Mavericc.
  #4 (permalink)  
Old 09-16-2008
Mavericc Mavericc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 5
Thumbs up Doesn't work on Solaris

Unfortunately this script does not work on Solaris.
The "&&" seems to be the culprit, as removing this stops throwing compilation error

Any help would be of much help.

Mavericc
  #5 (permalink)  
Old 09-16-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
Use /usr/xpg4/bin/awk on Solaris.

Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0