November 5, 2013

HOWTO Trim comments and spaces from files

Learn a quick and efficient way to remove comments and blank lines from config files using a simple grep command and regex—perfect for cleaner outputs and easier parsing.

Trim comments and spaces from a file:

$ grep ^[^#] file

“The regex ^[^#] matches the first character of any line, as long as that character that is not a #. Because blank lines don’t have a first character they’re not matched either, resulting in a nice compact output of just the active configuration lines.”

Via David Berner