Skip to content

Instantly share code, notes, and snippets.

@osvalr
Created March 18, 2017 20:45
Show Gist options
  • Save osvalr/3c91fe0c5ed079c2e3d1be386888bf62 to your computer and use it in GitHub Desktop.
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
#!/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