[英]Print non-ascii/unicode characters in shell
I am using following command to search and print non-ascii characters:我正在使用以下命令来搜索和打印非 ascii 字符:
grep --color -R -C 2 -P -n "[\x80-\xFF]" .
The output that I get, prints the line which has non-ascii characters in it.我得到的输出打印了其中包含非 ascii 字符的行。 However it does not print the actual unicode character.
但是它不会打印实际的 unicode 字符。
Is there a way to print the unicode character?有没有办法打印unicode字符?
./test.yml-35-
./test.yml-36-- name: Flush Handlers
./test.yml:37: meta: flush_handlers
./test.yml-38-
--
This was answered in Searching for non-ascii characters .这在Searching for non-ascii characters 中得到了回答。 The real issue as shown in Filtering invalid utf8 is that the regular expression you are using is for single bytes, while UTF-8 is a multibyte encoding (and the pattern must therefore cover multiple bytes).
过滤无效 utf8 中显示的真正问题是您使用的正则表达式是针对单个字节的,而 UTF-8 是多字节编码(因此该模式必须涵盖多个字节)。
The extensive answer by @ Peter O in the latter Q/A appears to be the best one, using Perl. @ Peter O在后一个 Q/A 中的广泛回答似乎是最好的,使用 Perl。 grep is the wrong tool.
grep 是错误的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.