com.mindprod.csv
Class CSVSort

java.lang.Object
  extended by com.mindprod.csv.CSVSort

public final class CSVSort
extends java.lang.Object

Sort a CSV file, on multiple columns with case sensitive, case insensitive and numeric fields.

Use: java.exe com.mindprod.CSVSort somefile.csv 0s+ 2i- 4n+ 5x+ 0-based list of column numbers, s=sensitive i=insensitive n=numeric x=hex +=ascending -=descending Empty cols are presumed to contain "" or "0".

This program has an unusual genesis. On 2009-12-03 I had a detailed dream about documenting and writing a sort for CSV files. When I woke up I was surprised at how logical the dream was. Usually my computer dreams, on waking, turn out to be complete nonsense. I wrote the program just as I planned it in the dream. All went unusually smoothly. About the only change was provision for ascending and descending keys.

Since:
2009-12-03
Version:
3.4 2010-12-03 - add CSV2SRS
Author:
Roedy Green, Canadian Mind Products

Constructor Summary
CSVSort(java.io.File file, int[] sortCols, char[] sortTypes, boolean[] isAscendings, char separatorChar, char quoteChar, char commentChar)
          pack a CSV file, constructor.
 
Method Summary
static void main(java.lang.String[] args)
          Simple command line interface to CSVSort, Sorts one csv file whose name is on the command line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVSort

public CSVSort(java.io.File file,
               int[] sortCols,
               char[] sortTypes,
               boolean[] isAscendings,
               char separatorChar,
               char quoteChar,
               char commentChar)
        throws java.io.IOException
pack a CSV file, constructor. Just create. There are no methods to call.

Parameters:
file - CSV file to be packed to remove excess space and quotes.
sortCols - array of 0-based cols to sort on.
sortTypes - array of chars with letters s i n x to tell how to sort each column.
isAscendings - array of sort direction, true=ascending, false = descending.
separatorChar - field separator character, usually ',' in North America, ';' in Europe and sometimes '\t' for tab.
quoteChar - char to use to enclose fields containing a separator, usually '\"'. Use (char)0 if you don't want a quote character.
commentChar - char to use to introduce comments. Use (char) 0 if none. Only one character allowed.
Throws:
java.io.IOException - if problems reading/writing file
Method Detail

main

public static void main(java.lang.String[] args)
Simple command line interface to CSVSort, Sorts one csv file whose name is on the command line. Must have extension .csv

Parameters:
args - name of csv file to remove excess quotes and space