Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

<para><text>
1.1.2 sometitle
</text></para>

with

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<para><p-title>
1.1.2 sometitle
</p-title></para>

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading