Wednesday, January 20, 2010

Perl Find and Replace One Liner

I'm constantly needing a way to easily change a line in a bunch of configuration files. I thought I'd share the way I do it here.

perl -p -i -e 's/oldstring/newstring/g' *

This allows you to use a regular expression and perform the find and replace.

2 comments:

  1. Why would you choose perl over sed? I'm just curious...

    ReplyDelete
  2. I don't think you can read and write to the same file with sed.

    ReplyDelete