The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Help in extracting data with command from file in C ahjiefreak High Level Programming 10 03-20-2008 11:26 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM
Extracting Data from a File oop UNIX for Dummies Questions & Answers 0 07-31-2007 11:48 AM
Extracting data from an AFP file Dolph UNIX for Advanced & Expert Users 4 05-22-2007 04:29 AM
extracting recursive data file bbeugie UNIX for Dummies Questions & Answers 1 06-16-2004 05:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-13-2007
nishana nishana is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
Question Extracting Data from xml file

Hi ppl out there...

Can anyone help me with the shell script to extract data from an xml file.

My xml file looks like :

- <servlet>
<servlet-name>FrontServlet</servlet-name>
<display-name>FrontServlet</display-name>
<servlet-class>com.americanexpress.util.frontservlet.FrontServlet</servlet-class>
- <init-param>
<param-name>configurator</param-name>
<param-value>XercesConfigurator</param-value>
</init-param>
- <init-param>
<param-name>configFile</param-name>
<param-value>/WEB-INF/ssofrontservletconfig.xml</param-value>
</init-param>
<load-on-startup>-1</load-on-startup>
</servlet>

I need to check whether the <param-name> is configFile and if it is , i have to extract the data in the <param-value> tag.

To extract the data from the <param-value> , i have the following code snippet.

/<param-value>/
{
stp1=index($0,">")+1;
newstr1=substr($0,stp1);
etp1=index(newstr1,"</param-value>")-1;
value=substr(newstr1,0,etp1);
}

Please help!
  #2 (permalink)  
Old 07-13-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
awk '/<param-name>configFile/{getline;print $3}' FS="[<>]" infile
Use nawk on Solaris.

Last edited by radoulov; 07-13-2007 at 07:01 AM.. Reason: correction
  #3 (permalink)  
Old 07-13-2007
nishana nishana is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
It works!

wow radoulov!....this is perfect!
thankx a million
  #4 (permalink)  
Old 07-13-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Please try this.....

Quote:
grep '<param-name>configFile' filename | sed 's!\(<param-name>configFile</\)\(.*\)\(>\)!\2!'
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 01:52 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