Matthias Leopold wrote:
hi,

Hello,

can someone please explain to me how to match patterns that contain newlines?

/\n/  or  /./s

when file.txt contains

aaa
bbb
ccc
ddd
eee

why doesn't

perl -pe 's/bbb.*?ddd//s;' file.txt

remove lines 2-4?

Because the -p switch creates a while loop that only reads one line at a time.

$ perl -MO=Deparse -pe 's/bbb.*?ddd//s;'
LINE: while (defined($_ = <ARGV>)) {
    s/bbb.*?ddd//s;
}
continue {
    print $_;
}
-e syntax OK


You need to either read the whole file at once:

perl -0777pe's/bbb.*?ddd//s' file.txt


Or don't print the lines you don't want:

perl -ne'/bbb/ .. /ddd/ or print' file.txt




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to