Remove Comments and Whitespace from Command Output

Often a Linux distribution or software package will add extensive and informative comments to a configuration file. One example of this is the Postfix main.cf file

While the comments can be invaluable, sometimes you want just the basic file without any extras.

To turn a heavily-annotated file into a bare file, you will need to remove 2 sets of lines:

This is straightforward with the sed command:

cat /etc/postfix/main.cf | sed -e '/^#/d' -e '/^$/d'

Questions? hit me up on Mastodon at @anthonyclarka2@bsd.network.