Browse Source

append_or_replace

master 0.8.0
pvincent 4 years ago
parent
commit
00dc3767a4
  1. 24
      tools/append_or_replace

24
tools/append_or_replace

@ -0,0 +1,24 @@
#!/bin/bash
usage() {
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
}
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
Loading…
Cancel
Save