Editing Files in Place with Ruby
October 3, 2007
One thing that's interesting about Ruby is that you can blatantly see the influence of other languages such as Lisp, Smalltalk, Perl and Java in it. One thing I always used to use Perl for is a simple search and replace tool:
perl -pi -e 's/foo/bar/g' *.txt
I recently discovered that there is a similar equivalent with Ruby:
ruby -pi -e "gsub(/foo/, 'bar')" *.txt