Unix命令查找非ascii字符

发布于 2024-10-06 12:43:37 字数 93 浏览 0 评论 0原文

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

谢谢 :)

I have a file 500MB of size.
It has some non-ascii characters in it. I just want to find out those characters using Unix command. May it will be better to get the line numbers and position at each line.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒江雪… 2024-10-13 12:43:37

使用其他解决方案中给出的答案,但将 -n 添加到 grep 中。

Use the answer given in the other solution, but add -n to grep.

鲜血染红嫁衣 2024-10-13 12:43:37

你知道,这很奇怪。有时我发现编写一些快速而肮脏的 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 范围之外的字符。

You know, it's weird. Sometimes I find it faster to code up some quick and dirty C than it is to try and navigate the wilderness of UNIX utility command line options :-)

#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;
}

This will give you both the line number, and the character position within that line, of any characters outside the ASCII range.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文