Find Unique Characters in a File

前端 未结 22 2291
耶瑟儿~
耶瑟儿~ 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:02

    Here's a PowerShell example:

    gc file.txt | select -Skip 2 | % { $_.ToCharArray() } | sort -CaseSensitive -Unique
    

    which produces:

    D
    Y
    a
    b
    o

    I like that it's easy to read.

    EDIT: Here's a faster version:

    $letters = @{} ; gc file.txt | select -Skip 2 | % { $_.ToCharArray() } | % { $letters[$_] = $true } ; $letters.Keys
    

提交回复
热议问题