Artificial intelligent assistant

Sed, remove all comments in a file I have a sed command that removes comments in a file as, sed -i /^#/d /path/to/file This works but not when the comments are indented/have a preceding space. like #this is a good comment ---- works #this is an indented comment ---- doesn't work How can i change it to remove lines that has # as the first visible character?

Modify your regex so that it allows for leading whitespace.


sed -e '/^[ \t]*#/d'


This regex will match lines beginning with 0 or more spaces or tabs (in any order), followed by a hash sign.

GNU sed also supports symbolic names:


sed -e '/^[[:space:]]*/d'


Which includes all whitespace characters, including the funny unicode foreign language ones. That's less portable, however.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 0108290f1befd327f44b7a1ee86ec735