Skip to content

Instantly share code, notes, and snippets.

@naganowl
Last active August 6, 2018 18:26
Show Gist options
  • Save naganowl/5502d58980667ae664791a94bcaacb00 to your computer and use it in GitHub Desktop.
Save naganowl/5502d58980667ae664791a94bcaacb00 to your computer and use it in GitHub Desktop.
Find/replace except in a directory
# https://stackoverflow.com/questions/18046456/excluding-a-directory-from-find-and-sed-rename
# https://stackoverflow.com/questions/9704020/recursive-search-and-replace-in-text-files-on-mac-and-linux
find app -type f -name '*.erb' -not \( -path 'app/views/helpers/*' \) -exec sed -i '' s/this/that/ {} +
# Given a file `sel` of strings, remove all instances of them in all other directories
for i in `cat sel` ; do echo $i | cut -c2- | find app -type f -name '*.erb' -not \( -path 'app/views/helpers/*' \) -exec sed -i '' "s/$i//" {} +; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment