Last active
November 3, 2015 17:00
-
-
Save ypresto/20213882618c6e650c35 to your computer and use it in GitHub Desktop.
Shell command for replacing all texts in all files under specified paths
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-inplace () { | |
if (( $# < 2 )); then | |
echo "sed-inplace FROM TO [PATH ...]" | |
return 1 | |
fi | |
from="$1" | |
to="$2" | |
shift 2 | |
ag -l "$from" "$@" | while read file; do | |
if [ "`uname`" = "Darwin" ]; then # please, please give me portable sed... | |
sed -i '' -e "s/$from/$to/g" "$file" | |
else | |
sed -i'' -e "s/$from/$to/g" "$file" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment