我有一些这样的文字:
This is some text Z书. This is Zsome more text Z计算机.
This is yet some more Z电脑 text Z.
我需要删除与模式Z+(CJK)
匹配的所有案例,其中(CJK)
是任意数量的连续CJK字符。上面的文件将变为:
This is some text . This is Zsome more text .
This is yet some more text Z.
如何删除与此模式匹配的所有CJK文本?
答案 0 :(得分:2)
Perl单线程怎么样?
perl -CSD -pe 's/Z\p{InCJK_Unified_Ideographs}+//g;' inputfile
答案 1 :(得分:2)
您可以使用GNU sed
检查非ASCII字符的代码:
sed -n l0 file.txt
结果:
This is some text Z\344\271\246. This is Zsome more text Z\350\256\241\347\256\227\346\234\272.$
This is yet some more Z\347\224\265\350\204\221 text Z.$
然后您可以使用GNU sed
进行所需的替换。在我的测试中,我必须将我的语言环境设置为POSIX:
LC_ALL="POSIX" sed -r 's/Z[\o200-\o377]+//g' file.txt
结果:
This is some text . This is Zsome more text .
This is yet some more text Z.