Source

bin / remove-comments.sh

#!/bin/sh

# Removes comment and empty lines from a file (from a configuration
# file).  Useful when you want to get only the active configuration
# values from a file.  Comment lines should be started with '#'
# character.

die () {
    echo >&2 "Error: $@"
    echo ""
    echo "Usage: remove-comments.sh filename"
    exit 1
}

# check input parameters
[ "$#" -gt 1 ] || die "1 argument required, $# provided"

grep -v -E '(^$|^#.*$)' $@