Skip to content

Instantly share code, notes, and snippets.

@haisum
Created September 1, 2015 06:10
Show Gist options
  • Save haisum/4fcd9146b6c972d0d3ca to your computer and use it in GitHub Desktop.
Save haisum/4fcd9146b6c972d0d3ca to your computer and use it in GitHub Desktop.
comment and uncomment lines in bash script via sed
sed -i '/<pattern>/s/^/#/g' file #comment
sed -i '/<pattern>/s/^#//g' file #uncomment
@IshuGitHub
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