Skip to content

Instantly share code, notes, and snippets.

@ypresto

ypresto/sed-inplace.sh

Last active Nov 3, 2015
Embed
What would you like to do?
Shell command for replacing all texts in all files under specified paths
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