Skip to content

Instantly share code, notes, and snippets.

@mikedfunk
Last active August 29, 2015 14:01
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 mikedfunk/40155989ded3f60bf783 to your computer and use it in GitHub Desktop.
Save mikedfunk/40155989ded3f60bf783 to your computer and use it in GitHub Desktop.
sed example
# search and replace with backup
# with -i it specifies a backup. So the file will be copied from myfile.txt to myfile.txt.bak before replacing any text.
# the * at the end is the filename. It can be myfile.* or *.txt or * or myfile.txt or whatever.
# mac version
sed -i .bak 's/hello/gbye/g' *
# linux version
sed -ibak 's/hello/gbye/g' *
# or just
sed 's/hello/gbye/g' *
# without backup
sed -i '' 's/hello/gbye/g' *
# specific file types
sed -i '' 's/hello/gbye/g' *.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment