I\'ve successfully used the following sed
command to search/replace text in Linux:
sed -i \'s/old_link/new_link/g\' *
However,
I've created a function to handle sed
difference between MacOS (tested on MacOS 10.12) and other OS:
OS=`uname`
# $(replace_in_file pattern file)
function replace_in_file() {
if [ "$OS" = 'Darwin' ]; then
# for MacOS
sed -i '' -e "$1" "$2"
else
# for Linux and Windows
sed -i'' -e "$1" "$2"
fi
}
Usage:
$(replace_in_file 's,MASTER_HOST.*,MASTER_HOST='"$MASTER_IP"',' "./mysql/.env")
Where:
,
is a delimeter
's,MASTER_HOST.*,MASTER_HOST='"$MASTER_IP"','
is pattern
"./mysql/.env"
is path to file