|
@ -1,6 +1,5 @@ |
|
|
#!/bin/bash |
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usage() { |
|
|
usage() { |
|
|
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>" |
|
|
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>" |
|
|
} |
|
|
} |
|
@ -14,11 +13,10 @@ REGEX=$1 |
|
|
STRING=$2 |
|
|
STRING=$2 |
|
|
FILE=$3 |
|
|
FILE=$3 |
|
|
|
|
|
|
|
|
grep -q "$REGEX" $FILE |
|
|
|
|
|
if [ $? -eq 1 ]; then |
|
|
|
|
|
|
|
|
if ! grep -q "$REGEX" "$FILE"; then |
|
|
echo "$STRING" >>$FILE |
|
|
echo "$STRING" >>$FILE |
|
|
echo appended |
|
|
echo appended |
|
|
else |
|
|
else |
|
|
sed -i "s/$REGEX/$STRING/g" $FILE |
|
|
|
|
|
|
|
|
sed -i "s|$REGEX|$STRING|g" $FILE |
|
|
echo replaced |
|
|
echo replaced |
|
|
fi |
|
|
fi |