Created
December 11, 2015 13:24
-
-
Save mvallebr/39cf10537baaf6f88f77 to your computer and use it in GitHub Desktop.
Replace strings in files using sed
This file contains hidden or 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
| #!/bin/ksh | |
| if [ "$#" -lt 3 ]; then | |
| echo "Usage: $0 alt_replace ORIGIN DEST FILEMASK" >&2 | |
| exit 1 | |
| fi | |
| ORIGIN_STRING=$1 | |
| REPLACEMENT_STRING=$2 | |
| for ORIG in $(grep -rl $ORIGIN_STRING ${*:3}) | |
| do | |
| echo "Replacing '$ORIGIN_STRING' by '$REPLACEMENT_STRING' in $ORIG" | |
| sed -i'' "s/$ORIGIN_STRING/$REPLACEMENT_STRING/g" "$ORIG" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment