You can use the -0
switch to change the input separator:
perl -0777pe 's/foo\nbar/FOO\nBAR/' baz.txt
-0777
sets the separator to undef
, -0
alone sets it to \0
which might work for text files not containing the null byte.
Note that /m
is needless as the regex does not contain ^
nor $
.
More Related Contents:
- string pattern matching using perl regex [closed]
- Awk – replace coumn 2 in table 1 from coumn 2 in table 2 based on matching data in column 1 (common between tables)
- I would like remove only spaces and ignore tabs in a string
- How do I match any character across multiple lines in a regular expression?
- Match whitespace but not newlines
- Should I use \d or [0-9] to match digits in a Perl regex?
- Using alternation or character class for single character matching?
- Why is a character class faster than alternation?
- Verbs that act after backtracking and failure
- What regex can match sequences of the same character?
- How to extract string following a pattern with grep, regex or perl [duplicate]
- regex to match word boundary beginning with special characters
- Regex to match any character including new lines
- Does the ‘o’ modifier for Perl regular expressions still provide any benefit?
- How do I handle special characters in a Perl regex?
- Why do ^ and $ not work as expected?
- How can I find the location of a regex match in Perl?
- How can I exclude some characters from a class?
- Can I use Perl regular expressions to match balanced text?
- What is the difference between \1 and $1 in a Perl regex?
- How do I perform a Perl substitution on a string while keeping the original?
- How can I match a quote-delimited string with a regex?
- How can I use a variable for a regex pattern without interpreting meta characters?
- Does \w match all alphanumeric characters defined in the Unicode standard?
- How can I parse quoted CSV in Perl with a regex?
- How can I match double-quoted strings with escaped double-quote characters?
- Is There a Way to Match Any Unicode Alphabetic Character?
- How to escape dollar sign ($) in a string using perl regex
- Capturing text before and after a C-style code block with a Perl regular expression
- Can I substitute multiple items in a single regular expression in VIM or Perl?