我需要从文件中删除包含 read (symbol)
匹配项的所有行,其中 (symbol)
是任何 CJK 字符。在匹配中,read (symbol)
紧接着是 A-Z 或 a-z,但是,不应删除该行。例如,以下是一些示例行和结果:
Do you like to read books? (not deleted)
Can you read 书? ( deleted)
.read 书. (deleted)
This is some thread 线. (not deleted)
如何仅删除与 (不是 A-Z 或 a-z)read(CJK 符号)匹配的行
?
最佳答案
我不完全确定如何匹配 CJK 字符,但如果您匹配非 ASCII 字符,您可能会获得您正在寻找的结果:
grep -vP "[^A-Za-z]read [\x80-\xFF]" file.txt
理论上,您应该能够做到:
grep -vP "[^A-Za-z]read [\x{2E80}-\x{9FBB}]+" file.txt
但是在我的测试中,我收到错误:
grep: character value in \x{...} sequence is too large
http://en.wikipedia.org/wiki/List_of_Unicode_characters#CJK_unified_ideographs
编辑:
LC_ALL="POSIX" sed -r '/[^A-Za-z]read [\o200-\o377]+/d' file.txt
结果:
Do you like to read books? (not deleted)
This is some thread 线. (not deleted)
另请参阅:
How to delete all CJK text appearing immediately after a particular symbol?
关于bash - 如何删除包含特定字符串的所有行,但仅当后面的字符是 CJK 字符时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12405864/