Getting rid of those pesky comments in your all important configuration files.
This is a tip from a recent edition Linux Journal which I’m sure they don’t mind me passing on as long as I mention that for the regular Linux user, Linux Journal is the best source of relevant news, tips, and inspirational stuff.
The idea is to take all the pesky comments out of one of those configuration files. Comments are preceded with a “#” sign, and often large sections of the config file are “commented out.” If you just want to see the parts that actually do something, try this:
grep ^[^#] /etc/ntp.conf
In this case, ntp.conf is the configuration file. (Note that the “etc’ directory tends to hold your configuration files. The reason for that is because technicaly, the way something works is you “install it, then, to make it work, you know, etc. etc. etc. ” )
This works because the grep command uses the regular expression code (the funny looking stuff) to match (or not match) each line in the file that is fed to it. If the match is good, the line is spewed into “standard output” which by default is your terminal.
The first ‘^’ anchors the rest of the regular expression to the beginning of a line. The second bit, with the [brackets] is where you can put characters to match. The second ‘^’ is not a ‘beginning of line’ thingie, but rather, in the context of the brackets, signifies the logical “not.” So, this looks for lines that do not have a “#” at the beginning. Blank lines are also not matched because the ‘^’ character does not work on them. Therefore, all blank lines and all comment lines are ignore by this grep command.
If you want to send this stripped down text into a file instead of just onto the screen, so you can play around with it more, just use redirection:
grep ^[^#] /etc/ntp.conf > /etc/ntp.nocomments.conf
The ‘>’ symbol, which is obviously an arrow, points standard output to whatever it is pointing to, in this case, a filename. If that file already exists, then it will be overwritten without warning. Which is good, because we don’t need no stinking warnings.




