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
<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