Searching and replacing a directory of files with `find`, `sed` and friends.
Here's how we globally search for and replace a deprecated relative require
statement in *_spec.rb
files.
find . -type f -name "*spec.rb" -exec sed -i '' 's/^require.*\/spec_helper.*$/require "spec_helper"/g' {} \;
and voila:
diff --git a/spec/controllers/api/book_prices_controller_spec.rb b/spec/controllers/api/book_prices_controller_spec.rb
index 013df6b..27a3c8a 100644
--- a/spec/controllers/api/book_prices_controller_spec.rb
+++ b/spec/controllers/api/book_prices_controller_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require "spec_helper"
Written by Andrew Hao
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sed
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#