Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
comment and uncomment lines in bash script via sed
sed -i '/<pattern>/s/^/#/g' file #comment
sed -i '/<pattern>/s/^#//g' file #uncomment
@rishavpathania1995

This comment has been minimized.

Copy link

rishavpathania1995 commented Feb 5, 2019

nice.

@IshuGitHub

This comment has been minimized.

Copy link

IshuGitHub commented Oct 12, 2019

This will add multiple # if executed multiple times..If you want to add # only once even after multiple times command execution then you can use this:
sed -e '/<pattern>/ s/^#*/#/g' -i file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.