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

Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top