使用perl用特殊字符替换字符串

Replace string with special characters using perl

我正在尝试替换像

这样的字符串
</string§>

new string line 1
new string line 2

在 Linux.

上使用 perl

问题是,它不接受 < 和 > 以及 /。

这是我得到的:

perl -i -pe 's/\<\/string§\>/new string line 1 \n new string line 2/se' file.xml

有人能帮忙吗?

谢谢!

您不需要 se 修饰符,也可以使用备用正则表达式分隔符(/ 除外)来避免转义:

perl -pe 's~</string§>~new string line 1 \nnew string line 2~' file.xml
new string line 1
new string line 2