How to view a configuration file without the comments

I have to often make changes to configuration files such as httpd.conf and squid.conf. These files have a large number of lines that are commented out, mostly comments and some possible configuration directives that have been commented out as they are not required by default. A problem I face while editing such files is that there are so many lines commented out that I need to scroll down many lines before I can find the next active configuration directive. I found a fine solution to help me out with this.

I now use the following command when I want to just look at the active directives in the Apache configuration file:

# sed ‘/ *#/d; /^ *$/d’ /etc/httpd/conf/httpd.conf

This command reads the file /etc/httpd/conf/httpd.conf and filters out all the comments and extra white spaces, leaving just the active configuration settings. This makes it very easy for me to look at the configuration file.

If you want to just filter out the lines that begin with comments run the following command:

# sed ‘/ ^#/d; /^ *$/d’ /etc/httpd/conf/httpd.conf

It’s pretty much the same command as earlier with a small change. The first * is replaced by ^, which is regex for beginning of line.

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.