Skip to content

Instantly share code, notes, and snippets.

@kevinthecity
Created May 26, 2023 20:15
Show Gist options
  • Save kevinthecity/4721c84c8a12ec0c35258776b75faba4 to your computer and use it in GitHub Desktop.
Save kevinthecity/4721c84c8a12ec0c35258776b75faba4 to your computer and use it in GitHub Desktop.
Find / Replace in directory
# ag <https://github.com/ggreer/the_silver_searcher>
# requires ag -> brew install the_silver_searcher
# usage: ag-replace.sh [search] [replace]
# caveats: will choke if either arguments contain a forward slash
# notes: will back up changed files to *.bak files. Remove the second line if you'd like to keep them
ag -0 -l $1 | xargs -0 sed -ri.bak -e "s/$1/$2/g";
git clean -f '**/*.bak';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment