Linux 很多设定档都会以 “#” 字符开头作为注解, 例如:
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
include /usr/share/nginx/modules/*.conf;
有些情况是要将注解行及空白行删除, 这样可以用 grep 指令实现, 语法是:
- $ grep -v ^\# config.conf | grep .
或者
- $ grep -v ^# configfile | grep -v ^$
上面第一个 grep 是将 “#” 字符开头的行过滤, 第二个 grep 是将空白行过滤掉.
如果要将已过滤注解及空白行的资料储存到档案, 用以下指令:
- $ grep -v ^\# config.conf | grep . >> newconf.conf
以上指令会将 config.conf 档案内的注解行及空白行过滤, 并将结果储存到 newconfig.conf 档案.