Replace search pattern containing newline followed by a digit using perl

I thought I had good grasp on perl oneliners but am having difficulty with this task.

I want to replace the following pattern in a text file

1.1.2 sometitle


1.1.2 sometitle

I tried a simple perl oneliner

perl -pe 's,<text>\n([0-9]+.*)\n</text>,<p-title>\1</p-title>,g' inputfile.xml

What am I missing here? Thanks.

>Solution :

You’re executing the program line each line of input, so you’ll never find a LF followed by something. Tell Perl to treat the whole file as one line using -0777 (or -g with very new versions of Perl).

perl -0777pe'...' inputfile.xml

Leave a Reply