From 8f9e4d54ecd9cca39c975b3107fb69a7b58e0057 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 29 Sep 2013 21:42:26 -0500 Subject: [PATCH] added pattern replacer. --- scripts/core/functions.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index 62e92d5b..6f447a74 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -325,6 +325,23 @@ if [ -z "$skip_all" ]; then done } + + # takes a file to modify, and then it will replace any occurrences of the + # pattern provided as the second parameter with the text in the third + # parameter. + function replace_pattern_in_file() + { + local file="$1"; shift + local pattern="$1"; shift + local replacement="$1"; shift + if [ -z "$file" -o -z "$pattern" -o -z "$replacement" ]; then + echo "replace_pattern_in_file: needs a filename, a pattern to replace, and the" + echo "text to replace that pattern with." + return 1 + fi + sed -i -e "s/$pattern/$replacement/" "$file" + } + function function_sentinel() { return 0; } if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi -- 2.34.1