4 ms·
What is everyone's current favorite one-liner for replacing a string in all files that match? In other words alternative implementations of this: ruby -pi
by lamontcg 4y ago
What is everyone's current favorite one-liner for replacing a string in all files that match?
In other words alternative implementations of this:
ruby -pi -e "gsub(/Net::HTTPServerException/, 'Net::HTTPClientException')" {lib,knife}/**/*.rb
- cutler 4y agoI think you need `ruby -i -ple` to handle newlines properly.
- michaelcampbell 4y agoAnd the perl version from which ruby's kind of sprang. perl -pi -e 's/from/to/g' list_of_files
- arp242 4y agosed -i? Not 100% portable across all implementations, but that usually doesn't matter. Some languages also have nice tools for this, such as gofmt -r; I don't know if something like that exists for Ruby.
- rascul 4y agofind with an -exec sed