Skip to content

Instantly share code, notes, and snippets.

@namklabs
Created July 19, 2012 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save namklabs/3145019 to your computer and use it in GitHub Desktop.
Save namklabs/3145019 to your computer and use it in GitHub Desktop.
find and replace on multiple files, preserve line endings
# This file operates on every file within the current directory and below, recursively.
# The original command is from http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux
# but has been modified to not mess with end of line characters (-b option in sed) according to http://stackoverflow.com/a/11508669
find . -name "*.html" -print | xargs sed -i -b 's/find/replacewith/g'
# This example command searches only .html files. This can be changed to anything.
# You need to specify what to find and what to replace it with (find/replacewith). These are regular expressions, so be careful of special characters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment