#!/bin/sh agr () { # find and replace regex=s/${1}/${2}/g; ag $1 -l | xargs sed -i.agr_backup $regex; # delete backups ag -G .agr_backup -l | xargs rm } # USAGE ON MAC OSX # 1. Install ag - https://github.com/ggreer/the_silver_searcher # 2. Copy lines 3 - 9 into your .bash_profile # 3. go to target directory and call with "agr" # EXAMPLE # Replace "test" with "hello" using "agr test hello"