Skip to content

Instantly share code, notes, and snippets.

@cocodrino
Created November 17, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocodrino/d42a49523181e4b1d2c1655f8b6583ac to your computer and use it in GitHub Desktop.
Save cocodrino/d42a49523181e4b1d2c1655f8b6583ac to your computer and use it in GitHub Desktop.
remove or add coments to line with some pattern in some file through command line...ideal for dockerfiles
comment is
sed -i '/<pattern>/s/^/#/g' file
And to uncomment it:
sed -i '/<pattern>/s/^#//g' file
In your case:
sed -i '/2001/s/^/#/g' file (to comment out)
sed -i '/2001/s/^#//g' file (to uncomment)
comments line with text 2001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment