Failed to get value from a file using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Failed to get value from a file using sed command
# 1  
Old 03-11-2006
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
# 2  
Old 03-11-2006
replace single quote ['] with DOUBLE quote ["] around the sed directive.

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

# 3  
Old 03-11-2006
Hi vgersh99,

Thanks a lot!!
It works fantastic!!

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What does the sed command here exactly doing to csv file?

I have the following csv file at the path; now using sed command. what is this exactly doing. sed -i 's//,/g' /FTP/LAB_RESULT_CM.csv Thank you very much for the helpful info. (2 Replies)
Discussion started by: cplusplus1
2 Replies

2. UNIX for Advanced & Expert Users

Resume from last failed command

Dear Experts, I am creating a shell script (A) which is menu driven and in turn calls another shell scripts (X) depending on the selection. X has a list of commands which runs batch jobs in auto mode. Content of X ./sqr.ksh axhri051_sf axhri051_sf.par $1 $2 XHRPPYOV; ./sqr.ksh axbni062... (19 Replies)
Discussion started by: rprasad
19 Replies

3. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

4. Shell Programming and Scripting

File formating (sed command)

I am new ot unix. Is there one or two lines of command (sed may be) to format a file. My source is.. <tag1> <tag2> <datatag1> data1 </datatag1> <datatag2> data2 </datatag2> <datatag3> data3 </datatag3> <datatag4> data1 </datatag3> </tag2> </tag1> (2 Replies)
Discussion started by: reachsam11
2 Replies

5. Shell Programming and Scripting

Rename file using sed command

Greetings, I am very new to the UNIX shell scripting and would like to learn. However, I am currently stuck on how to process the below sample : Filename : DOCabcdef24387987ab90d.xml Pattern "DOC"+any character using and +".xml" And i want to change the second part of that file (any... (20 Replies)
Discussion started by: fanny_tirtasari
20 Replies

6. Solaris

command 'cc' failed even though gcc is installed

I'm trying to build some python modules on a Solaris 10 machine. It has gcc as /usr/sfw/bin/gcc. # CC=gcc python setup.py build running build running build_py running build_ext cc -c actread.c -o actread.o unable to execute cc: No such file or directory error: command 'cc' failed with exit... (8 Replies)
Discussion started by: aussieos
8 Replies

7. Shell Programming and Scripting

use argument file with sed command

I am trying to delete lines from a file with the sed command. I have two files. File a.txt 200,000 records. Here is a sample of the file. File a.txt 2401ABC0212345678 plus 250 characters of other data 2401ABC0212345678 plus 250 characters of other data 2402ABC0212345678 plus... (3 Replies)
Discussion started by: robbanigan
3 Replies

8. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. Shell Programming and Scripting

Script exits with $? not 0 randomly, how can I see what command failed?

Hi! I have this situation with 3 shellscripts. One is a "startscript" that simply calls other scripts. This one is scheduled with cron to run at regular intervals. That script runs what I'll refer to as Script 1. Script 1 in turn runs script 2 (import_catalogs_buyer.sh) Sometimes, seemingly... (2 Replies)
Discussion started by: trailsmoke
2 Replies

10. Shell Programming and Scripting

Rerunning a command in a script that failed?

I have a script that occasionally has a command here and there that fails and I would like to set my script up to just re run the command if the exit code is 1. Is there a simple way to do that without if/thens or redirecting to the command again? (5 Replies)
Discussion started by: trey85stang
5 Replies
Login or Register to Ask a Question