Find Unique Characters in a File

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

    While not an script this java program will do the work. It's easy to understand an fast ( to run )

    import java.util.*;
    import java.io.*;
    public class  Unique {
        public static void main( String [] args ) throws IOException { 
            int c = 0;
            Set s = new TreeSet();
            while( ( c = System.in.read() ) > 0 ) {
                s.add( Character.toLowerCase((char)c));
            }
            System.out.println( "Unique characters:" + s );
        }
    }
    

    You'll invoke it like this:

    type yourFile | java Unique
    

    or

    cat yourFile | java Unique
    

    For instance, the unique characters in the HTML of this question are:

    Unique characters:[ , , ,  , !, ", #, $, %, &, ', (, ), +, ,, -, ., /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, [, \, ], ^, _, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, {, |, }]
    

提交回复
热议问题