Find Unique Characters in a File

前端 未结 22 2283
耶瑟儿~
耶瑟儿~ 2021-02-04 03:30

I have a file with 450,000+ rows of entries. Each entry is about 7 characters in length. What I want to know is the unique characters of this file.

For instance, if my f

22条回答
  •  别跟我提以往
    2021-02-04 04:05

    Quick and dirty C program that's blazingly fast:

    #include 
    
    int main(void)
    {
      int chars[256] = {0}, c;
      while((c = getchar()) != EOF)
        chars[c] = 1;
      for(c = 32; c < 127; c++)  // printable chars only
      {
        if(chars[c])
          putchar(c);
      }
    
      putchar('\n');
    
      return 0;
    }
    

    Compile it, then do

    cat file | ./a.out
    

    To get a list of the unique printable characters in file.

提交回复
热议问题