From df6eb09e6c7ce53df0caf754fe2a8d8272ca319e Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 1 Feb 2015 21:55:29 -0500 Subject: [PATCH] new multi-file pattern search and replace. --- scripts/core/search_replace.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/core/search_replace.sh diff --git a/scripts/core/search_replace.sh b/scripts/core/search_replace.sh new file mode 100644 index 00000000..9825c6ca --- /dev/null +++ b/scripts/core/search_replace.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# a break out of the popular replace_pattern_in_file function that +# can work with multiple files. + +source "$FEISTY_MEOW_SCRIPTS/core/functions.sh" + +pattern="$1"; shift +replacement="$1"; shift + +if [ -z "$1" -o -z "$pattern" -o -z "$replacement" ]; then + echo This script requires a simple pattern to search for in a set of files, + echo the replacement for the pattern, and a list of files. + exit 1 +fi + +# loop across the file names we were given. + +while true; do + patt1="$1"; shift + if [ -z "$patt1" ]; then + break; + fi + + for currfile in $patt1; do + replace_pattern_in_file "$currfile" "$pattern" "$replacement" + done + +done + -- 2.34.1