如何删除特定符号后立即出现的所有CJK文本?(How to delete all CJK text

2019-10-17 05:42发布

我有这样一些文字:

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文本匹配该模式?

Answer 1:

您可以使用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.


Answer 2:

怎么样一个Perl的单行?

perl -CSD -pe 's/Z\p{InCJK_Unified_Ideographs}+//g;' inputfile


文章来源: How to delete all CJK text appearing immediately after a particular symbol?
标签: bash grep