Hacker News new | past | comments | ask | show | jobs | submit login

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



sed -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.


And the perl version from which ruby's kind of sprang.

    perl -pi -e 's/from/to/g' list_of_files


I think you need `ruby -i -ple` to handle newlines properly.


find with an -exec sed




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: