Skip to content

Instantly share code, notes, and snippets.

@pesterhazy pesterhazy/frpl.sh
Last active Jul 9, 2018

Embed
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
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' "$@"
@pesterhazy

This comment has been minimized.

Copy link
Owner Author

pesterhazy commented Jul 9, 2018

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

[alias]
	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.