Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Multiline search and replace in file(s)

by AnomalousMonk (Bishop)
on Aug 09, 2020 at 08:18 UTC ( #11120516=note: print w/replies, xml ) Need Help??


in reply to Multiline search and replace in file(s)

Note that this will deal with Mary and her little lamb over any line boundaries:

c:\@Work\Perl\monks>perl use strict; use warnings; use autodie; my $data = <<EOD; Mary Had A Little Lamb She Was GOOD Not Changing this Or This Mary Had A Little Lamb She Was GOOD Line 9 Line 10 EOD open my $fh, '<', \$data; my $content = do { local $/; <$fh>; }; print "[[$content]] \n\n"; $content =~ s{ Mary \s+ Had \s+ A \s+ Little \s+ Lamb \s+ She \s+ Was \s+ GOOD } {CHANGED!!!}xmsg; print "<<$content>> \n"; __END__ [[Mary Had A Little Lamb She Was GOOD Not Changing this Or This Mary Had A Little Lamb She Was GOOD Line 9 Line 10 ]] <<CHANGED!!! Not Changing this Or This CHANGED!!! Line 9 Line 10 >>


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-10-21 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (217 votes). Check out past polls.

    Notices?