Created
March 18, 2017 20:45
-
-
Save osvalr/3c91fe0c5ed079c2e3d1be386888bf62 to your computer and use it in GitHub Desktop.
for-sed-grep script, this is used to replace a string in a set of files without doing sed n-times
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/bash | |
# for-grep-sed script used to match a string and replace it in set of files | |
FGS_FIELD=$1; | |
FGS_FIELD_REPLACEMENT=$2; | |
for mf in `grep -rn ${FGS_FIELD} --include=\*.{xml,py} | tr ":" " " | awk '{print $1}' | uniq`; do | |
sed_replace="sed -i 's/${FGS_FIELD}/${FGS_FIELD_REPLACEMENT}/g' ${mf}"; | |
eval $sed_replace; | |
done | |
unset FGS_FIELD; | |
unset FGS_FIELD_REPLACEMENT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment