I had to sort and uniq (create a unique set of strings) a large list with lots of duplicate. Ho dovuto ordinare e uniq (creare un unico insieme di stringhe) un elenco di grandi dimensioni con un sacco di duplicati. My options were to write it in Java or download cygwin and run: cat file | sort | uniq > result Le opzioni sono state per scrivere in Java o cygwin scaricare ed eseguire: cat file | sort | uniq> risultato

Cygwin download never works for me. Cygwin scaricare mai opere per me. After I spend lots of time selecting a juicy list of utilities, it always fails somewhere in the download process. Dopo aver spendere un sacco di tempo la selezione di un succoso elenco dei servizi di pubblica utilità, non riesce sempre in qualche parte del processo di download. I liked it much better when it was a single download. Mi piaceva molto meglio quando si è trattato di un singolo download.

I opted for Java route naturally. Ho optato per Java percorso naturale. After all it was just a single line of code really. Dopo tutto era solo una sola riga di codice realmente.

for(String item:getFileAsSet(args[0])) System.out.println(item); for (String voce: getFileAsSet (args [0])) System.out.println (voce);

Obviously you are wondering where the heck do I get getFileAsSet . Ovviamente si sono chiedendo dove il heck posso ottenere getFileAsSet. It is just one of the many reusable java utilities I created to make my job easier. E 'solo uno dei tanti servizi di pubblica utilità riutilizzabili java ho creato per rendere più facile il mio lavoro. The crucial part of the code for this utility is: La parte cruciale del codice per questa utilità è:

 TreeSet  set = new TreeSet serie = new TreeSet  (); while((temp = reader.readLine()) != null) {             temp = temp.trim(); // Hate spaces; Your mileage may vary             if(temp.length() > 0) {                  set.add(temp);             } } (); While ((temp = reader.readLine ())! = Null) (temp = temp.trim (); / / Hate spazi; vostra situazione potrebbe essere diversa se (temp.length ()> 0) (set.add (TEMP);)) 

The beauty of this code is that TreeSet is a SortedSet implementation. La bellezza di questo codice è che TreeSet è un SortedSet attuazione. Adding to the Set automatically ensures elimination of duplicates as well as sorting. Aggiungendo a favore di una serie garantisce automaticamente che l'eliminazione di duplicati e la cernita. All I had to do was just print the result. Tutto quello che ho dovuto fare è stato solo il risultato di stampa.