sed: parsing tnsnames.ora


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed: parsing tnsnames.ora
# 1  
Old 10-19-2010
sed: parsing tnsnames.ora

All:

Can sombodoy help me out with a sed command? Assume I have the following:
Code:
PRI =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pri)
      (INSTANCE_NAME = pri)
    )
  )

STDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stdby)
      (INSTANCE_NAME = stdby)
    )
  )


AIXSNAP =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.0.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = aixsnap)
      (INSTANCE_NAME = aixsnap)
    )
  )


I would like to get the line right above (DESCRIPTION. Keep in mind that there may or may not be spaces between the '(' and the word DESCRIPTION. So valid examples can be something like this:

Code:
 
(DESCRIPTION= 
( DESCRIPTION= 
(DESCRIPTION  = 
(    DESCRIPTION = 

The output I am looking for should be like this
Code:
 
 PRI
 STDBY
 AIXSNAP

Thanks in advance to all who help!!!

Last edited by Scott; 10-19-2010 at 03:13 PM.. Reason: Code tags, please...
# 2  
Old 10-19-2010
Code:
$ awk -F"[ =]" '/DESCRIPTION/ { print X }{ X=$1 }' tnsnames.ora
PRI
STDBY
AIXSNAP

This User Gave Thanks to Scott For This Post:
# 3  
Old 10-19-2010
Code:
$ awk '!/^\(/ && $2== "=" {print $1}' file
PRI
STDBY
AIXSNAP

# 4  
Old 10-19-2010
Code:
sed -n -e "/DESCRIPTION/{g;s/ .*=.*//p;}" -e "h" file

This User Gave Thanks to anbu23 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Ora-27603:ora-27626:

Hi, User claim that job is running slow from their end. I DBA found in database the below errors in alert log file. ORA-27603: Cell storage I/O error, I/O failed on disk o/192.168.10.3/RECO_DM01_CD_01_drm01 at offset 13335789568 for data length 1048576 ORA-27626: Exadata error: 2201 (IO... (2 Replies)
Discussion started by: Maddy123
2 Replies

2. AIX

I cannot find dsn and TNSNAMES.ora on UNIX

Where can I find dsn and TNSNAMES.ora on UNIX AIX Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

3. Shell Programming and Scripting

Removing section from tnsnames.ora

Hi, I am trying to write a script or command to remove a section from tnsnames.ora file in the following example I would like to remove tns_alias2 section $ cat tnsnames.ora tns_alias1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host1 )(PORT = 1521)) ... (3 Replies)
Discussion started by: ynixon
3 Replies

4. Shell Programming and Scripting

Parsing Listener.ora

Anymore have any code to easily parse the listener.ora to update the ORACLE_HOME for a specific sid? thanks. (1 Reply)
Discussion started by: nugent
1 Replies

5. Shell Programming and Scripting

Tnsnames.ora

Hi, I would like to modify, in script schell, the line right above (DESCRIPTION and check three cases : if line contain ".world" then line=line-".world" concat "," concat line if line dont contain ".world" then line=line concat "," concat line concat".world" else line=line Keep in... (10 Replies)
Discussion started by: elcaro
10 Replies

6. Shell Programming and Scripting

sed (parsing value)

All, Can somebody provide me with some sed expertise on how to parse the following line. 27-MAR-2011 10:28:01 * (CONNECT_DATA=(SID=dmart)(CID=(PROGRAM=sqlplus)(HOST=mtasnprod1)(USER=mtasnord))) * (ADDRESS=(PROTOCOL=tcp)(HOST=10.197.7.47)(PORT=54881)) * establish * dmart * 0 I would like... (3 Replies)
Discussion started by: BeefStu
3 Replies

7. UNIX for Advanced & Expert Users

grep all ORA errors except one ORA error

Hi - I am trying to grep all "ORA" errors in a log files.I have to grep all ORA errors except one error for example ORA-01653.How can exclude that error in "grep" command? In following "grep" command I want to exclude "ORA-01653" error grep -i ORA alert.log >>/tmp/ora_errors.txt ... (7 Replies)
Discussion started by: Mansoor8810
7 Replies

8. Solaris

maxuprc and maxusers - ORA-27300, ORA-27301, ORA-27302

Hi all, Am intermittently getting the following errors on one of my databases. Errors in file /oracle/HRD/saptrace/background/hrd_psp0_13943.trc: ORA-27300: OS system dependent operation:fork failed with status: 12 ORA-27301: OS failure message: Not enough space ORA-27302:... (1 Reply)
Discussion started by: newbie_01
1 Replies

9. UNIX for Dummies Questions & Answers

find tnsnames.ora in unix

Can we find out what is the location of tnsnames.ora file used by the hp unix. (3 Replies)
Discussion started by: Sudipshib
3 Replies

10. Shell Programming and Scripting

Need to capture the service name from tnsnames.ora and create connect string

ghkjkjoj (4 Replies)
Discussion started by: chetankelvin
4 Replies
Login or Register to Ask a Question