Skip to content

Instantly share code, notes, and snippets.

@madsonic
Created June 25, 2019 03:20
Show Gist options
  • Select an option

  • Save madsonic/669bec3ba87887bc726cfe9e6f7b89b6 to your computer and use it in GitHub Desktop.

Select an option

Save madsonic/669bec3ba87887bc726cfe9e6f7b89b6 to your computer and use it in GitHub Desktop.
search and replace file content
# mac
sed 's/<target>/<replacement>/g' <inputfile> > <outputfile>
# inplace
sed -i '.bck' 's/<target>/<replacement>/g' <inputfile>
# only if FOO appears in the line
sed 'FOO/s/<target>/<replacement>/g' <inputfile>
# multiple command
sed -e 's/<target>/<replacement>/g' -e 's/<target>/<replacement>/g' <inputfile>
# + delimiter
sed 's+<target>+<replacement>+g' <inputfile>
# s: search and replace
# g: global
# I: case insensitive
# delimiter can be + instead of slash to avoide confusion with similar characters
# -i : save file with given suffix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment