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.