Use Shell scripts to format tnsnames. ora content case 1

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.