During parameter configuration, you must first check the content in tnsnames. ora. If the tns string to be configured already exists in the file, direct the parameter to a tns string.
During parameter configuration, you must first check the content in tnsnames. ora. If the tns string to be configured already exists in the file, direct the parameter to a tns string.
I recently summarized the workload during the working process and found that the parameter configuration for developers occupies a large part. So I want to use shell scripts to simplify workflow operations and reduce the workload.
During parameter configuration, you must first check the content in tnsnames. ora. If the tns string to be configured already exists in the file, direct the parameter to a tns string. If the tns string does not exist, add the tns string to tnsnames. ora, and set related parameters.
In our work, we are sure to view tnsnames through cat. ora, then confirm whether the tns string exists by combining the pipeline and grep, but this is usually too cumbersome. We want to simply write a shell script, and then we only need to replace tnsnames. ora is passed in as a parameter to output relevant results and prompt corresponding operations.
During the script writing process, tnsnames is the first problem. the formats of tns strings in ora are inconsistent: Some tns strings are in the same row, and some tns strings are divided into several lines. In this case, we need to format the file format. To facilitate subsequent operations, we decided to sort all the tns strings into one row.
The main content of the formatting script is as follows:
Sed '/^ $/d' $1 | sed's // G' | sed': a; N; $! Ba; s/\ = \ n/\ =/G' | sed ': a; N; $! Ba; s/\ n (/G' | sed ': a; N; $! Ba; s/\ n)/G'> tnsnames. result
The main idea of the script is:
1. First remove the blank lines and spaces in tnsnames. ora.
2. Sort the rows starting with (and) into one row.
3. Redirect the processed result to a file and save it.
For sed ': a; N ;! Ba; s/\ n (/G' command explanation:
: A creates a tag.
N append the current row and the next row to the mode space.
If ba is in front of the last line, jump to the previous tag
$! Ba ($! This operation is not followed by the last row. The last row is specially processed .)
The operations after finding whether the tns string exists are relatively simple and skipped.
This article permanently updates the link address: