Only use awk to Remove invalid information such as comments in the configuration file.

Source: Internet
Author: User

Only use awk to Remove invalid information such as comments in the configuration file.

Question: Only awk is used to remove comments and empty lines from the configuration file;

Note: 1. the configuration file comment is # Start, end to the end of the line, and is similar to the comment in shell;

2. comments, including comments at the beginning and end of the line;

3. blank lines, including lines containing only line breaks and blank lines;


 

Solution:

1. Only remove comments, end comments, and blank lines:

 

Awk-F' # ''($1) {print $1} 'xxx. conf

2. You can only remove comments from lines, comments at the end of a line, empty lines, and blank lines:

Awk-F #'{($1 & $1 !~ /^ [[: Blank:] * $/) {print $1} 'xxx. conf

Equivalent method:

Awk-F' #''($1 & $1 !~ /^ [\ T] * $/) {print $1} 'xxx. conf

3. Add the row number in the original configuration file for each valid row:

Awk-F' #''($1 & $1 !~ /^ [[: Blank:] * $/) {print NR, $1} 'xxx. conf


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.