如何从 shell 中识别非 ASCII 字符?

use*_*001 13 linux grep perl awk ascii

有没有一种简单的方法来打印所有非ASCII字符和它们使用命令行实用程序,如在文件中出现的行号grepawkperl,等?

我想将文本文件的编码从 UTF-8 更改为 ASCII,但在此之前,希望手动替换所有非 ASCII 字符实例,以避免文件转换例程影响的意外字符更改。

Red*_*ick 17

$ perl -ne 'print "$. $_" if m/[\x80-\xFF]/'  utf8.txt
2 Pour être ou ne pas être
4 By? ?i neby?
5 ???
Run Code Online (Sandbox Code Playgroud)

或者

$ grep -n -P '[\x80-\xFF]' utf8.txt
2:Pour être ou ne pas être
4:By? ?i neby?
5:???
Run Code Online (Sandbox Code Playgroud)

utf8.txt 在哪里

$ cat utf8.txt
To be or not to be.
Pour être ou ne pas être
Om of niet zijn
By? ?i neby?
???
Run Code Online (Sandbox Code Playgroud)