繁体   English   中英

在 shell 中打印非 ascii/unicode 字符

[英]Print non-ascii/unicode characters in shell

我正在使用以下命令来搜索和打印非 ascii 字符:

grep --color -R -C 2 -P -n "[\x80-\xFF]" .

我得到的输出打印了其中包含非 ascii 字符的行。 但是它不会打印实际的 unicode 字符。

有没有办法打印unicode字符?

输出

./test.yml-35-
./test.yml-36-- name: Flush Handlers
./test.yml:37:  meta: flush_handlers
./test.yml-38-
--

这在Searching for non-ascii characters 中得到了回答。 过滤无效 utf8 中显示的真正问题是您使用的正则表达式是针对单个字节的,而 UTF-8 是多字节编码(因此该模式必须涵盖多个字节)。

@ Peter O在后一个 Q/A 中的广泛回答似乎是最好的,使用 Perl。 grep 是错误的工具。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM