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: Perl










September 20th, 2004 at 3:34 pm
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.