20 lines
333 B
Plaintext
Executable File
20 lines
333 B
Plaintext
Executable File
#!/usr/bin/env miaou-bash
|
|
|
|
function usage {
|
|
builtin echo "Usage: $(basename "$0") <FILE> <REGEX> <STRING>"
|
|
}
|
|
|
|
[[ $# -ne 3 ]] && usage && exit 2
|
|
|
|
FILE=$1
|
|
REGEX=$2
|
|
STRING=$3
|
|
|
|
if ! grep -Pq "$REGEX" "$FILE"; then
|
|
builtin echo -e "$STRING" >>"$FILE"
|
|
echo 'appended'
|
|
else
|
|
sed -Ei "s|$REGEX|$STRING|g" "$FILE"
|
|
echo 'replaced'
|
|
fi
|