Skip to content

Instantly share code, notes, and snippets.

@restrepo
Last active December 11, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save restrepo/4566188 to your computer and use it in GitHub Desktop.
Save restrepo/4566188 to your computer and use it in GitHub Desktop.
REGEX raplacement in a list of files
#!/usr/bin/env bash
pattern=$1
replace=$2
list=$3
if ! [ $replace ]; then
echo USAGE: $0 PATTERN REPLACEMENT LIST
echo EXAMPLE: $0 \""R-\\([a-z]\\+\\)"\" \"\\\$R\\\$-"\1"\" \"\*.tex\"
fi
for i in $list; do
sed 's/'"$pattern"'/'"$replace"'/g' $i > /tmp/tmpfile
if [ $(diff $i /tmp/tmpfile| wc -l) -gt 0 ]; then
mv /tmp/tmpfile $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment