LINUX: Grep 命令去空行

今天学习了 grep 命令一个小技巧,即 “去空行”, grep 命令能够非常方便地查看配置文件哪些参数被修改了,今天测试了把,用来处理 PostgreSQL 的配置文件 postgresql.conf。

1 查看 postgresql.conf 文件中被修改的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[postgres@redhat6 pg_root]$ cat postgresql.conf | grep -v "^$" | grep -v "^#"
# (change requires restart)
# (change requires restart)
# (change requires restart)
# (change requires restart)
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 1922 # (change requires restart)
max_connections = 100 # (change requires restart)
# (change requires restart)
# (change requires restart)
# (change requires restart)
# (change requires restart)
# 0 selects the system default
# 0 selects the system default
# 0 selects the system default
shared_buffers = 32MB # min 128kB
# (change requires restart)
# (change requires restart)
# in kB, or -1 for no limit
# (change requires restart)
wal_level = archive # minimal, archive, or hot_standby
# (change requires restart)
# off, local, remote_write, or on
# supported by the operating system:
# open_datasync
# fdatasync (default on Linux)
# fsync
# fsync_writethrough
# open_sync
# (change requires restart)
checkpoint_segments = 3 # in logfile segments, min 1, 16MB each
checkpoint_timeout = 2min # range 30s-1h
checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = '/bin/date' # command to use to archive a logfile segment
...
..省略部分

备注:符号 ^ 表示匹配一行的开始; $ 表示匹配一行的结束; 所示 ^# 表示空行。 因此去掉 postgresql.conf 中的空行,并且排除掉以 # 打头的行,即为已更改的配置文件参数。

2 查看 postgreql.conf 中值为 “on” 的参数

1
2
3
4
[postgres@redhat6 pg_root]$ cat postgresql.conf | grep "= on$" | grep -v "^#"  
log_checkpoints = on
log_connections = on
track_activities = on

3 查看 postgreql.conf 中值为 “off” 的参数

1
2
[postgres@redhat6 pg_root]$ cat postgresql.conf | grep "= off$" | grep -v "^#"  
log_disconnections = off

4 附件 postgresql.conf
本来想上传 postgresql.conf ,网易 blog 居然不支持上传txt 格式文件,熟悉 postgresql 的朋友应该都知道这个配置文件,这里就不上传了。

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%