鑑於在私人使用區字符的文件,如:如何刪除包含專用區域字符的行?
$ cat textfile.txt | less
10 翴 30 <U+E4D1> ten-thirty in ... three ... two ... one .
- 10 翴 45だи<U+E145>砆 秂 <U+E18E> it 's a slam-dunk .
<U+E707> 10 翴 <U+E6C4>ㄓ ? so you will be home by 10:00 ?
10 翴 牧 よ<U+E6BC>ㄓ<U+E5EC> bogey at 10 o'clock .
- 10 翴 牧 よ<U+E6BC>い盠 - ten o'clock , lieutenant , 10 o'clock !
10 翴 牧 よ<U+E6BC>綽玭 i see it , 8 o'clock , heading south !
10 翴 筁<U+E5EC> it 's past 10:00 .
<U+E80B>ぱ 10 翴 非<U+E1A0>筁ㄓ be here tomorrow , 10:00 sharp .
- 10 , 老搭檔 有 人 開槍 , 疑犯 拒捕 shots firing . suspect 's fleeing .
- 1 -0 而已 - only 1-0 .
- 1 -0 而已 - only 1-0 .
如何刪除一條線,如果有遇到超出Unicode字節點的任何字符?
我已經試過這樣:
# ord(u'\uE000') == 57344
for line in open('test.txt'):
if any(ord(i) >57344 for i in line):
pass
else:
print (line)
但我似乎無法擺脫包含PUA字符的各線。
如何在unix bash中使用sed/awk或其他方法實現相同的功能而不是使用Python?
注意,我仍想保留是有效的Unicode而不是僅僅保持與ASCII字符行線。例如。我想保留最後三行的漢字,「......射擊,嫌疑人逃跑」。 (出於某種原因,我無法在問題中鍵入中文部分,因爲SO顯示中文字符錯誤)。
請注意,我不是要刪除非英文字符。如果有任何字符落入PUA,我試圖刪除整行。我仍然想保持像' - 10,老搭檔有人開槍,疑犯拒捕射擊。嫌疑人逃跑。「# – alvas