CLKF Course: Strip out Comments and Blank Lines with Grep (Linux/Unix)
Linux Training Academy
http://www.linuxtrainingacademy.com/strip-out-comments-blank-lines-grep
Use the following grep command to strip out comments and blank lines
$ grep -Ev "^#|^$" file
The -E options enables extended regular expressions. This allows us to use the pipe to represent the "or" condition in our pattern. The -v option inverts the match meaning that grep will only print lines that do not match our search pattern. The "^#" pattern matches all lines that begin with a pound sign (#) while the "^$" pattern matches all the blank lines.
[jason@linuxsvr etc]$ head /etc/sysctl.conf
Kernel sysctl configuration file for Red Hat Linux
For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
sysctl.conf(5) for more details.
Controls IP packet forwarding
net.ipv4.ip_forward = 0
Controls source route verification
net.ipv4.conf.default.rp_filter = 1 [jason@linuxsvr etc]$ grep -Ev '^#|^$' sysctl.conf net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 4294967295 kernel.shmall = 268435456 [jason@linuxsvr etc]$
http://www.linuxtrainingacademy.com ... https://www.youtube.com/watch?v=36HjCU4LXQM
6173948 Bytes