Editing Files in Place with Ruby

8:03 PM EDT Wednesday, 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

Posted in  | Tags Perl, Ruby

Comments Feed

1. Awesome! Thanks for sharing this.

# Posted By Alex on Thursday, July 31 2008 at 12:56 EDT

Add a Comment