【问题标题】:Unix command to find non-ascii chars用于查找非 ascii 字符的 Unix 命令
【发布时间】:2011-05-21 09:35:12
【问题描述】:

我有一个 500MB 大小的文件。 它有一些非ASCII字符。我只想使用 Unix 命令找出这些字符。可能会更好地获取每行的行号和位置。

谢谢:)

【问题讨论】:

  • 您可以在stackoverflow.com/questions/3001177/…找到答案
  • @vpit3833:我对 unix 命令不是很熟悉,我认为该链接没有提供那些非 ascii 字符的行号。如果我错了,我很抱歉......

标签: file unix command non-ascii-characters


【解决方案1】:

使用the other solution 中给出的答案,但将-n 添加到grep

【讨论】:

    【解决方案2】:

    你知道,这很奇怪。有时我发现编写一些快速而肮脏的 C 代码比尝试浏览大量 UNIX 实用程序命令行选项更快:-)

    #include <stdio.h>
    
    int main (void) {
        size_t ln = 1;
        size_t chpos = 0;
        int chr;
        while ((chr = fgetc (stdin)) != EOF) {
            if (chr == '\n') {
                ln++;
                chpos = 0;
                continue;
            }
            chpos++;
            if (chr > 127) {
                printf ("Non-ASCII %02x found at line %d, offset %d\n",
                    chr, ln, chpos);
            }
        }
        return 0;
    }
    

    这将为您提供 ASCII 范围之外的任何字符的行号和该行中的字符位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 2010-12-26
      • 2013-11-17
      • 1970-01-01
      相关资源
      最近更新 更多