Skip to content

Instantly share code, notes, and snippets.

@fedecarg
Last active December 14, 2015 15:29
Show Gist options
  • Save fedecarg/5108050 to your computer and use it in GitHub Desktop.
Save fedecarg/5108050 to your computer and use it in GitHub Desktop.
Search and replace in files

Search

grep -Irl --include=\*.txt "keyword" .

or

find . -type f -print0 | xargs -0 grep "keyword"

Search and Replace

Recursively search a directory for files containing "this" and replace it with "that":

find . -type f -print0 | xargs -0 sed -i 's/this/that/g'

or

sed -i 's/this/that/g' `grep -lR --include=\*.txt 'this' .`

If you are on a Mac:

find . -name '*.txt' | xargs perl -pi -e 's/this/that/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment