Suppose that you would like to read a config file without comments. For example we have config.conf file as follows:
# my config.conf file example # set conf variable to 0 conf = #0; # end config.conf file
Following grep command assumes that each comment starts with single # character at the beginning of the line. To remove or ignore all comments from a file a following grep command can be used:
$ grep -v ^\# config.conf | grep . conf = 0;
NOTE:"grep ." also removes all empty lines from a file.
One reason to ignore all comment lines is to see relevant config settings of any particular conf file. As an example /etc/hdparm.conf contains 137 lines.
$ cat /etc/hdparm.conf | wc -l
137
when removing comment lines we get:
$ grep -v ^\# /etc/hdparm.conf | grep . quiet