Select the contents respective to some specific content from a file and move it to an output file
1
vote
2
answers
87
views
I have a file tnsnames.ora and its contents are as below.
NEWDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1550))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = newdb)
)
)
LISTENER_DG11G =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1550))
)
LISTENER_SABDB =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1550))
)
STEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = STEST)
)
)
RBSDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = linuxerp.de.mph.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = RBSDB)
)
)
In the above file
NEWDB =
LISTENER_DG11G =
LISTENER_SABDB =
STEST =
RBSDB =
are the database names and the respective service names are included in SERVICE_NAME =
So, From the above file I am trying to extract the Database name and respective service names and put it into a file or .xls in linux.
The output file should be like
NEWDB newdb
STEST STEST
RBSDB RBSDB
And what all databases that don't have service name should not be added into the output file.
I tried using CSPLIT
and move the first set of lines to a file "X" and select the first line and SERVICE_NAME using cat X | grep -i "SERVICE_NAME" | cut -d "=" -f2 | rev | cut -d ")" -f2 | rev | awk "NF"
and move it to a file and append the same way to rest of database names.
But it seems so complicated. Any other idea how it can be done will be appreciated.
Asked by sabarish jackson
(628 rep)
Mar 21, 2017, 04:00 AM
Last activity: Mar 21, 2017, 12:27 PM
Last activity: Mar 21, 2017, 12:27 PM