Skip to content

Instantly share code, notes, and snippets.

@mikybars
Last active February 15, 2019 23:55
Show Gist options
  • Save mikybars/d6cebf40a840e58ad866e6de9ecef9f9 to your computer and use it in GitHub Desktop.
Save mikybars/d6cebf40a840e58ad866e6de9ecef9f9 to your computer and use it in GitHub Desktop.
We have two options here: * `sed` is a powerful **stream** editor although it also features a handy in-place/`-i` flag that may modify the source file. Unfortunately this is a non-standard FreeBSD extension and therefore results in unportable code.
# Replace the shell executing the script
$ ex - '+g/^#!/s,bash,zsh,' -cwq install.sh
# Comment all non-commentary lines
$ ex - '+g/^[[:space:]]*[^#]/s/^/#/' -cwq test.sh
# Replace the shell executing the script
$ sed -i -e 's,bash,zsh,' install.sh
# sed can also create a backup file if an extension is provided to the -i flag
$ sed -i.bak -e 's/private/public/' MyClass.java
$ ls MyClass.*
Myclass.java MyClass.java.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment