【问题标题】:Print non-ascii/unicode characters in shell在 shell 中打印非 ascii/unicode 字符
【发布时间】:2015-09-14 15:11:06
【问题描述】:

我正在使用以下命令来搜索和打印非 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-
--

【问题讨论】:

    标签: linux shell unicode non-ascii-characters


    【解决方案1】:

    这是在Searching for non-ascii characters 中回答的。 Filtering invalid utf8 中显示的真正问题是您使用的正则表达式用于单字节,而 UTF-8 是多字节编码(因此该模式必须覆盖多个字节)。 p>

    后一个问答中@Peter O 的大量answer 似乎是最好的,使用Perl。 grep 是错误的工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2010-12-14
      • 2012-10-14
      相关资源
      最近更新 更多