new multi-file pattern search and replace.
authorChris Koeritz <fred@gruntose.com>
Mon, 2 Feb 2015 02:55:29 +0000 (21:55 -0500)
committerChris Koeritz <fred@gruntose.com>
Mon, 2 Feb 2015 02:55:29 +0000 (21:55 -0500)
scripts/core/search_replace.sh [new file with mode: 0644]

diff --git a/scripts/core/search_replace.sh b/scripts/core/search_replace.sh
new file mode 100644 (file)
index 0000000..9825c6c
--- /dev/null
@@ -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
+