Created
July 18, 2014 16:54
-
-
Save sibnerian/ea8b5617bbea9571293d to your computer and use it in GitHub Desktop.
Using sed to replace text in file on Mac OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed_replace() { | |
# require all 3 parameters | |
if [ .$1 = . ] || [ .$2 = . ] || [ .$3 = . ]; then | |
echo "Usage: sed_replace [oldString] [newString] [targetFile]" | |
return 0 | |
fi | |
local oldString=$1 | |
local newString=$2 | |
local targetFile=$3 | |
local temp=`mktemp -t sed_replace.XXXXXXXXX` | |
chmod ug+rw $temp | |
sed 's/'$oldString'/'$newString'/g' $targetFile > $temp | |
mv $temp $targetFile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sed -i "${3##*.}" s/$1/$2/g $3