Created
May 16, 2016 17:05
-
-
Save sgbett/a6d50316a6fa98b07fbd3b617aa9d454 to your computer and use it in GitHub Desktop.
sed & grep commands for locating uses of 'find_by_X(some_param)' and replacing with where(X: some_param)
This file contains 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
#search project for occurances | |
grep -R find_by_ app/* | awk 'BEGIN {FS=":"}{print $1}' | uniq | |
#copy original file to .bak and do replacements of find_by with where | |
for F in $(grep -R find_by_ app/* | awk 'BEGIN {FS=":"}{print $1}' | uniq); do | |
mv $F $F.bak | |
sed 's/find_by_id(\(.*\))/where(id: \1).first/g' $F.bak > $F | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(note: this will fail where more than one set of brackets is present on the same line)