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
URGENT: Script/Function needed to read text property files in block wise ysreenivas Shell Programming and Scripting 7 05-11-2009 03:08 AM
Problem with Calling sql file from shell script sskc Shell Programming and Scripting 1 05-03-2007 05:20 PM
printing last argument in shell script arunkumar_mca Shell Programming and Scripting 5 10-03-2006 08:32 PM
Problem with SU or SSH in shell script sravanp UNIX for Dummies Questions & Answers 2 01-24-2006 12:00 PM
end of file problem with shell script whatisthis Shell Programming and Scripting 5 10-20-2004 03:20 PM

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 04-16-2008
neeto neeto is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 28
Problem printing the property of xml file via shell script

Hi,
I have a config.xml which cointains the tags like
<CONFIG>
<PROPERTY name="port" value="1111"/>
<PROPERTY name="dbname" value="ABCDE"/>
<PROPERTY name="connectstring" value="xyz/pwd"/>
</CONFIG>
This file is in some directory at UNix box.
I need to write a shell script to echo the dbname.

Please help me with the sample shell script fpr this.



Thanks in advance
  #2 (permalink)  
Old 04-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
sed -n 's%<PROPERTY name="dbname" value="\([^"]*\)".*%\1%p' file.xml
The proper way to do it is with XSLT but if this is all you need, that's overkill.
  #3 (permalink)  
Old 04-16-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Code:
 awk -F'"' '$2=="dbname" {print $4}' file.xml
  #4 (permalink)  
Old 04-16-2008
neeto neeto is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 28
Thanks for the reply..
But is there a way to do this in awk?

Neha
  #5 (permalink)  
Old 04-16-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Code:
[n]awk '{
  if ($2 ~ /dbname/) {
     gsub(/(^.*=\"|\"\/>$)/,"",$NF)
     print $NF
  }
}' file
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 08:18 PM.


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