简体   繁体   English

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

[英]Replace string with special characters using perl

I'm trying to replace a string like 我正在尝试替换一个字符串

</string§>

with

new string line 1
new string line 2

with perl on Linux. 在Linux上使用perl。

The problem is, that it won't accept the < and > as well as the /. 问题是,它将不接受<和>以及/。

This is what i got: 这就是我得到的:

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

Can anyone help? 有人可以帮忙吗?

Thanks! 谢谢!

You don't need s and e modifiers and can also use an alternate regex demiter (other than / ) to avoid escaping: 您不需要se修饰符,还可以使用其他正则表达式除法器( /除外)来避免转义:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM