Skip to content

Instantly share code, notes, and snippets.

Forked from hlissner/
Last active May 16, 2017
What would you like to do?
Bulk search & replace with ag (the_silver_searcher)

Bulk search & replace with ag (the_silver_searcher)

# ag <>
# usage: [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