» Cat a file, without the comments
I recently had to install a couple of squid servers to act as reverse proxies for a webcluster. You can teach the squid server to stand in between in the end users and the webservers, and to store all the static content ( .jpg .flv .css .htm for example ) in the RAM. This saves a lot of I/O and bandwidth on the webservers, and it can really speeds up a site. And the end of the road the webservers' load dropped with 92%. But before all this worked, I had to run through a massive config file and since the squid config file is their manual at the same time, it's about 5000 lines long. So I had to find out a way to filter only the important settings from the config file.
This is what i came up with:
cat /etc/squid/squid.conf | egrep -v "(^#.*|^$)"
Explained
egrep -v means leave the following out
^#.* means patterns that begin with a #
| means or
^$ means patterns that are empty
Updates
update #1
Thanks to an insightfull comment by Darwin Award Winner on this article, here's a version that would also filter comments with spaces before the #, such as comments that are indented with code blocks:
cat /etc/squid/squid.conf | egrep -v "^\s*(#|$)"
Thanks Darwin!
Like this article?
|
Then Digg it! Or use another bookmark button below to show your support & help me spread the word. |
Hot StuffFlaming articles» Survive heavy traffic with you... | RelatedArticles like this one» Block brute force attacks with... |
tags: linux, cat, comments, squid, config file
category: How to - System
read: 2,101 times






tagcloud
#3. aptgetupdate.de on 31 July 2007
#2. Kevin (link) on 31 July 2007
#1. Darwin Award Winner on 31 July 2007
If you also wanted to remove comments at the ends of lines, you could pipe the output through sed 's/\s+#.*$//'
... [more] cat /etc/squid/squid.conf | egrep -v "^\s*(#|$)" | sed -e 's/\s+#.*$//'
You could create a script /usr/local/bin/conconf (catconf as in cat config files, or make up a more creative name) with the following contents (remember to make it executable):
#!/bin/sh
cat "$@" | egrep -v "^\s*(#|$)" | sed -e 's/\s+#.*$//'