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