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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rm & mv command failed due to too many files. videsh77 UNIX for Advanced & Expert Users 9 05-16-2008 11:01 AM
Problem with Mail command: exec failed. errno=2. hawkman2k UNIX for Dummies Questions & Answers 1 04-29-2008 06:50 AM
Fatal error: Command failed for target `build_crypto' sayed_021 SUN Solaris 1 02-13-2008 08:16 AM
Solaris 9: make: Fatal error:Command failed for target eldiego UNIX for Dummies Questions & Answers 2 10-28-2005 12:11 PM
Editing file during running ksh in HP failed nir_s Shell Programming and Scripting 2 08-05-2004 05:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2006
Registered User
 

Join Date: Jun 2004
Posts: 146
Stumble this Post!
Failed to get value from a file using sed command

Hi folks,

I have the following file (tnsnames.ora):
Code:
DB10g =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = buffy)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = DB10g)
   )
 )

EXTPROC_CONNECTION_DATA =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
   )
   (CONNECT_DATA =
     (SID = PLSExtProc)
     (PRESENTATION = RO)
   )
 )
I'm trying to get the listener port in my ksh program by the following command:
Code:
buffy:/tmp # echo $CONNECT_STRING
DB10g
buffy:/tmp # echo $ORACLE_HOME
/home/oracle/v10.1.0
buffy:/tmp # export DB_LISTENER_PORT=`sed -n '/"'"${CONNECT_STRING}"'"/,/CONNECT_DATA/ s/^.*PORT =.*\([0-9]\{4\}\).*$/\1/p' $ORACLE_HOME/network/admin/tnsnames.ora `
buffy:/tmp # echo $DB_LISTENER_PORT
As you can see,the parameter is empty.

But if I replace the parameter $CONNECT_STRING with hard-coded value ,it will work:
Code:
buffy:/tmp # export DB_LISTENER_PORT=`sed -n '/DB10g/,/CONNECT_DATA/ s/^.*PORT =.*\([0-9]\{4\}\).*$/\1/p' $ORACLE_HOME/network/admin/tnsnames.ora `
buffy:/tmp # echo $DB_LISTENER_PORT
1521
Why the sed command failed to replace the parameter $CONNECT_STRING with its value?

Thanks in advance,
Nir
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-11-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
replace single quote ['] with DOUBLE quote ["] around the sed directive.

Code:
sed -n "/${CONNECT_STRING}/,/CONNECT_DATA/ s/^.*PORT =.*\([0-9]\{4\}\).*$/\1/p"
Reply With Quote
  #3 (permalink)  
Old 03-11-2006
Registered User
 

Join Date: Jun 2004
Posts: 146
Stumble this Post!
Hi vgersh99,

Thanks a lot!!
It works fantastic!!

Best regards,
Nir
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0