How to remove comments from a config file with sed
Strip comment lines and inline comments from configuration files using sed regex patterns.
How to remove comments from a config file with sed
Strip comment lines and inline comments from configuration files using sed regex patterns.
Prerequisites
- sed installed.
Step-by-Step: Remove Comments with sed
Remove lines that start with
#(full-line comments):sed '/^#/d' config.confRemove lines that start with
#and blank lines:sed '/^#/d; /^$/d' config.confRemove inline comments (everything after
#on a line):sed 's/#.*$//' config.confCombine all three — remove comment lines, blank lines, and inline comments:
sed '/^#/d; /^$/d; s/#.*$//' config.confApply in-place:
sed -i '/^#/d; /^$/d; s/#.*$//' config.conf