Failed to get value from a file using sed command

Hi folks,

I have the following file (tnsnames.ora):

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:

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:

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

replace single quote ['] with DOUBLE quote ["] around the sed directive.

sed -n "/${CONNECT_STRING}/,/CONNECT_DATA/ s/^.*PORT =.*\([0-9]\{4\}\).*$/\1/p"

Hi vgersh99,

Thanks a lot!!
It works fantastic!!

Best regards,
Nir