jamin on September 13th, 2004

Since I generally prefer using Perl rather than handfuls of commands such as sed, awk, tr, cut, when I see a post like this I feel the strange need to post a Perl one-liner version.

perl -pi -e 'undef $/;s/I(\s+)hope/we$1expect/g' file.txt

Before you run this, beware that I’m using in-place editing (-i) so it will overwrite the file. If you don’t want to use in-place editing:

perl -pe 'undef $/;s/I(\s+)hope/we$1expect/g' file.txt > output.txt

Tags:

One Response to “Multi-line editing in Perl”

  1. Alas, cygwin is screwing with me again …

    It ALWAYS creates a .bak file. I haven’t been able to figure out how to get perl to not do that in cygwin.