Removing section from tnsnames.ora


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing section from tnsnames.ora
# 1  
Old 10-25-2015
Wrench 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

Code:
$ cat tnsnames.ora
tns_alias1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host1 )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = service1)
    )
  )

tns_alias2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host2 )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = service2)
    )
  )

tns_alias3 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host3 )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = service3)
    )
  )

$ sed ......

$ cat tnsnames.ora
tns_alias1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host1 )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = service1)
    )
  )

tns_alias3 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host3 )(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = service3)
    )
  )

any ideas ?
# 2  
Old 10-25-2015
Try:
Code:
sed '/tns_alias2 /,/^ *$/d' file

or

Code:
awk '$1!="tns_alias2"' RS= ORS='\n\n' file

The commands use empty lines as section separator, so a precondition is that they are present between blocks. That awk example only works if the separating lines are completely empty (i.e. two consecutive newlines)..
# 3  
Old 10-25-2015
Thanks, the sed command works fine on that file, but the file can not always has spaces like I mentioned.
The file can be like this:

Code:
$ cat tnsnames.ora
tns_alias1=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=host1)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=service1)
)
)
tns_alias2=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=service2)
)
)
tns_alias3=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=host3)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=service3)
)
)

# 4  
Old 10-25-2015
Might benefit from some fine tuning:
Code:
awk '
/^tns_alias2/   {getline
                 L+=gsub (/\(/, "") - gsub (/\)/,"")
                }

!L
L               {L+=gsub (/\(/, "") - gsub (/\)/,"")
                }

' file

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting section and removing match

I have a file with contents as shown in file.texi Would like to keep only the sections that have inlineifset till the empty line is reached. Finally replace the following string with a space @inlineifset{mrg, @opar{@bullet{} I had written the following command but it messed my file ... (6 Replies)
Discussion started by: Danette
6 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 sections from listener.ora

Hi, I am trying to write a script or command to add/remove a section from listener.ora file in the following example I would like: 1. to remove sid_alias2 sections 2. to add a new alias sections called sid_alias4, it can be placed after sid_alias3 sections $ cat listener.ora ... (18 Replies)
Discussion started by: ynixon
18 Replies

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

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

6. Shell Programming and Scripting

sed: parsing tnsnames.ora

All: Can sombodoy help me out with a sed command? Assume I have the following: PRI = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pri) ... (3 Replies)
Discussion started by: BeefStu
3 Replies

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

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

9. Shell Programming and Scripting

Removing Duplicate Lines per Section

Hello, I am in need of removing duplicate lines from within a file per section. File: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5 593.5000 ... (5 Replies)
Discussion started by: petersf
5 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