Skip to content

Instantly share code, notes, and snippets.

@sgbett
Created May 16, 2016 17:05
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 sgbett/a6d50316a6fa98b07fbd3b617aa9d454 to your computer and use it in GitHub Desktop.
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)
#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
@sgbett
Copy link
Author

sgbett commented May 16, 2016

(note: this will fail where more than one set of brackets is present on the same line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment