Skip to content

Instantly share code, notes, and snippets.

@pesterhazy pesterhazy/
Last active Jul 9, 2018

What would you like to do?
Fixed-string replace in multiple files. Change files in place
#!/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
export FIND="$1"
export REPLACE="$1"
exec perl -i -ne '$f=quotemeta($ENV{"FIND"}); $t=$ENV{"REPLACE"}; s/$f/$t/g; print' "$@"

This comment has been minimized.

Copy link
Owner Author

pesterhazy commented Jul 9, 2018

To use from git, add this to your ~/.gitconfig

	frpl = "!f() { [ \"$GIT_PREFIX\" != \"\" ] && cd \"$GIT_PREFIX\"; git ls-files -z | xargs -0 frpl \"$@\" ; } ; f"

Then you can use:

git frpl <FROM> <TO>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.