Skip to content

Instantly share code, notes, and snippets.

@mkarmona
Forked from hlissner/replace.sh
Created April 25, 2017 10:44
Show Gist options
  • Select an option

  • Save mkarmona/f35fe0a1bc4b3dd325132d859ced263d to your computer and use it in GitHub Desktop.

Select an option

Save mkarmona/f35fe0a1bc4b3dd325132d859ced263d to your computer and use it in GitHub Desktop.
Bulk search & replace with ag (the_silver_searcher)
# ag <https://github.com/ggreer/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
ag -l $1 | xargs perl -pi.bak -e "s/$1/$2/g"
# or if you prefer sed's regex syntax:
ag -l $1 | xargs sed -ri.bak -e "s/$1/$2/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment