diff --git a/tools/append_or_replace b/tools/append_or_replace new file mode 100755 index 0000000..077c859 --- /dev/null +++ b/tools/append_or_replace @@ -0,0 +1,24 @@ +#!/bin/bash + + +usage() { + echo "Usage: $(basename "$0") " +} + +if [[ $# -ne 3 ]]; then + usage + exit 2 +fi + +REGEX=$1 +STRING=$2 +FILE=$3 + +grep -q "$REGEX" $FILE +if [ $? -eq 1 ]; then + echo "$STRING" >> $FILE + echo appended +else + sed -i "s/$REGEX/$STRING/g" $FILE + echo replaced +fi