【发布时间】:2019-11-28 00:12:22
【问题描述】:
考虑一下这个README.md,它包含许多非ascii unicode 字符。
我想使用 bash 提取所有唯一的非 ascii 字符(最好在 OSX 上)。
例如,我想作为输出:
²
³
½
×
–
‖
→
↔
∀
∂
∆
∈
≈
≥
️
????
????
目前,我有一个比较繁琐的命令,不知道是否可以改进:
LC_ALL=C cat README.md | sed -n "s/\(.\)/\1 /pg" | tr ' ' '\n' | grep '[^ -~]' | sort | uniq
related question, but awk-based answers are printed as byte-code
【问题讨论】:
-
我会使用 perl:
perl -CiIO -nle '$h{$_}++ for /\P{ASCII}/g;END{print for keys %h}' /path/to/README.md。这可以很容易地更改以对它们进行排序或显示每个有多少。