Last active
July 9, 2018 14:26
Star
You must be signed in to star a gist
Fixed-string replace in multiple files. Change files in place
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
#!/usr/bin/env bash | |
set -euo pipefail | |
# Fixed-string replace in multiple files. Changes files in place | |
if [[ $# -lt 3 ]]; then | |
echo "Syntax: frpl <from-string> <to-string> <file1> [file2 file3 ....]" | |
exit 1 | |
fi | |
export FIND="$1" | |
shift | |
export REPLACE="$1" | |
shift | |
exec perl -i -ne '$f=quotemeta($ENV{"FIND"}); $t=$ENV{"REPLACE"}; s/$f/$t/g; print' "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use from git, add this to your
~/.gitconfig
Then you can use: