Skip to content

Instantly share code, notes, and snippets.

@ypresto
Last active November 3, 2015 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypresto/20213882618c6e650c35 to your computer and use it in GitHub Desktop.
Save ypresto/20213882618c6e650c35 to your computer and use it in GitHub Desktop.
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