Here’s a little script I wrote that lets you do search and replace with confirmation in bash. It uses find so it can look recursively through your files and uses vim to do the actual searching and replacing.

#Usage ./viSearchReplace <original> <new> <filename or directory>
if [ $# -ne 3 ]; then
        echo "Usage:    ./viSearchReplace <original> <new> <filename or directory>"
        exit 1
for i in `find $3 ! -type d ! -name . ! -name .. ! -name $0`; do
    vim -c '%s/'$1'/'$2'/gc' -c 'wq' $i
exit 0

GitHub Link

Leave a Reply

Your email address will not be published. Required fields are marked *