Skip to content

Instantly share code, notes, and snippets.

@DavidPu
Last active September 26, 2017 16:41
Show Gist options
  • Save DavidPu/d2b919544ae5bbbd0ff9583acfd646ab to your computer and use it in GitHub Desktop.
Save DavidPu/d2b919544ae5bbbd0ff9583acfd646ab to your computer and use it in GitHub Desktop.
sed cheatsheet

http://www.thegeekstuff.com/2009/09/unix-sed-tutorial-replace-text-inside-a-file-using-substitute-command/comment-page-1/

find pattern and insert after match in same line:

https://stackoverflow.com/questions/35252285/insert-text-with-sed-on-the-same-line-that-pattern-search sed 's/\blocalhost\b/& 192.168.25.50/' file

match pattern and replace the line:

sed -i "/export TOP=/c export TOP="${TOP}"" *.sh

match pattern and delete the line:

sed -i "/export TOP=/d" *.sh

insert before line:

sed -i "/export TOP=/i newline" *.sh

insert after line:

sed -i "/export TOP=/a newline" *.sh

array

http://www.thegeekstuff.com/2010/06/bash-array-tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment