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

时间:2016-02-04 22:39:41

标签: regex linux perl special-characters

我正在尝试替换像

这样的字符串
</string§>

new string line 1
new string line 2

在Linux上使用perl。

问题是,它不会接受&lt;和&gt;以及/.

这就是我得到的:

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

有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

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

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