Remove/Add Comment from config file using sed [duplicate]

Something like this would work:

sed '/^#/{s/^#//;b};/./s/^/#/' infile

more readable:

sed '
    /^#/ {       # If a line starts with "#"
        s/^#//   # Remove the leading "#"
        b        # Move to next line
    }
    /./s/^/#/      # If the line is not empty, prepend "#"
' infile