Cross platform sed
#!/bin/bash
case "$OSTYPE" in
darwin*) PLATFORM="OSX" ;;
linux*) PLATFORM="LINUX" ;;
bsd*) PLATFORM="BSD" ;;
*) PLATFORM="UNKNOWN" ;;
esac
replace() {
if [[ "$PLATFORM" == "OSX" || "$PLATFORM" == "BSD" ]]; then
sed -i "" "$1" "$2"
elif [ "$PLATFORM" == "LINUX" ]; then
sed -i "$1" "$2"
fi
}
replace "s/foo/bar/g" file.txt