linux过滤文本空行和注释

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/networken/article/details/88066162

文本内容示例:

$ cat postgresql.conf
# These are only used if logging_collector is on:
log_directory = 'log'                   # directory where log files are written,
                                        # can be absolute or relative to PGDATA
log_filename = 'postgresql-%a.log'      # log file name pattern,
                                        # can include strftime() escapes
# log_file_mode = 0600                                          # creation mode for log files,
                                        # begin with 0 to use octal notation

log_truncate_on_rotation = on           # If on, an existing log file with the
                                        # same name as the new log file will be
                                        # truncated rather than appended to.
                                        # But such truncation only occurs on
                                        # time-driven rotation, not on restarts
                                        # or size-driven rotation.  Default is
                                        # off, meaning append to existing files
                                        # in all cases.

需求描述:

仅保留有效配置,过滤掉所有注释行。

过滤命令:

$ cat postgresql.conf | grep -v "^[[:space:]].*#" | grep -v "^#" | grep -v "^$"

执行效果:

$ cat postgresql.conf | grep -v "^[[:space:]].*#" | grep -v "^#" | grep -v "^$"               
log_directory = 'log'                   # directory where log files are written,
log_filename = 'postgresql-%a.log'      # log file name pattern,
log_truncate_on_rotation = on           # If on, an existing log file with the
log_rotation_age = 1d                   # Automatic rotation of logfiles will
log_rotation_size = 0                   # Automatic rotation of logfiles will

猜你喜欢

转载自blog.csdn.net/networken/article/details/88066162