Script day – read configuration files

This is not really a script – more of a snippet. I don’t have a lot of spare time these days, so I can justify posting a snippet and calling it “script day” 😉 .

A lot of unix configuration files use the # sign to add comments to configuration files, and a lot of software comes with very well documented files – i.e. has lots of comments. So much that if you just want a quick glimpse at the configuration that is active (not commented out) its very difficult to wade through all the documentation.

Here’s a simple grep that will filter out all the junk and leave you with just the active configuration settings:

egrep -v '^(#|\s*$)' <config file>

and on the standard output you’d get only lines that are not commented out or empty.

Do note that some configuration files can also use ; as a comment character, but modifying the grep to support this is trivial.

2 Responses to “Script day – read configuration files”

  1. amit:

    That prints ONLY the junk 😉
    You probably mean ‘egrep -v’

  2. Guss:

    Yes, of course – silly mistake – I fixed.

Leave a Reply



%d bloggers like this: