Browse Source

fix: append_or_replace works for '/' chars

master
pvincent 3 years ago
parent
commit
4ff123a203
  1. 10
      tools/append_or_replace

10
tools/append_or_replace

@ -1,6 +1,5 @@
#!/bin/bash
usage() {
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
}
@ -8,17 +7,16 @@ usage() {
if [[ $# -ne 3 ]]; then
usage
exit 2
fi
fi
REGEX=$1
STRING=$2
FILE=$3
grep -q "$REGEX" $FILE
if [ $? -eq 1 ]; then
echo "$STRING" >> $FILE
if ! grep -q "$REGEX" "$FILE"; then
echo "$STRING" >>$FILE
echo appended
else
sed -i "s/$REGEX/$STRING/g" $FILE
sed -i "s|$REGEX|$STRING|g" $FILE
echo replaced
fi
Loading…
Cancel
Save