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
Reading multiple tags from .asx files underlig Shell Programming and Scripting 0 11-25-2006 01:27 AM
Removing leading and trailing spaces of data between the tags in xml. jhmr7 UNIX for Dummies Questions & Answers 2 05-18-2005 11:27 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 08-04-2008
pvr_satya pvr_satya is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 12
how to get data from xml files tags(from data tags)

i have a file like

<fruits>
<apple>redcolor<\apple>
<banana>yellow color and it is<\banana>
</fruits>

i need a text between apple and bannana ans so on....

how to read a text between a tags it multiple tags with differnt names
  #2 (permalink)  
Old 08-04-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
This should help you with a perl script:

XML::Simple - Easy API to maintain XML (esp config files) - search.cpan.org
  #3 (permalink)  
Old 08-04-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,448

Code:
awk -F'[<|>]' '/<apple>/{f=1}/<banana>/{f=""}f{print $3}' file

  #4 (permalink)  
Old 08-04-2008
pvr_satya pvr_satya is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 12
Quote:
Originally Posted by danmero View Post
Code:
awk -F'[<|>]' '/<apple>/{f=1}/<banana>/{f=""}f{print $3}' file
how can i find data if multiple tags present ( i mean dynamically)
  #5 (permalink)  
Old 08-04-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,448
Quote:
Originally Posted by pvr_satya View Post
how can i find data if multiple tags present ( i mean dynamically)
Did you try my solution?
  #6 (permalink)  
Old 08-04-2008
pvr_satya pvr_satya is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 12
Quote:
Originally Posted by danmero View Post
Code:
awk -F'[<|>]' '/<apple>/{f=1}/<banana>/{f=""}f{print $3}' file
thanx for u r ans its working

suppose in my file i have multiple lines of differnt tags
then how to get data
  #7 (permalink)  
Old 08-04-2008
Sarala Anugu Sarala Anugu is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 5
nawk -F">" '{print $2}' file | nawk -F"<" '{print $1}' | grep . | grep your-pattern

with this method you are not hardcoding the tagnames, instead we are getting the string between > and the following <

hence the output of this command is
sa865h@sipc306> nawk -F">" '{print $2}' file | nawk -F"<" '{print $1}' | grep .
redcolor
yellow color and it is

"grep ." will simply remove the empy lines

Hope it is useful!!!!!!!!!!!!!
Closed Thread

Bookmarks

Tags
extract data from xml

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 06:13 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