Skip to main content

## sort

The sort command sorts CSV input data on one or more fields. You can specify ascending and descending order, and use alphabetic or numeric comparisons. In order to perform a sort, CSVfix currently reads all data into memory prior to sorting - you should therefore be cautious about using this command on very large data files.
See also: shuffle

Flag | Req'd? | Description
-f fields | No | Specifies a comma-separated list of fields to sort on. If not specified, the data is sorted on the first field only. For example, -f 4,1 specifies that the data should be sorted using field 4 , and within that field on field 1:. Each field number in the list may be flowed by a number of flags, separated from the field number by a colon. The following flags are currently supported: A or D - specifies Ascending (the default) or Descending order
S, I or N - specifies whether the field is sorted as a String (alphabetically, the default), as a string Ignoring case differences, or as a Number. If sorting as a number, all fields must contain valid numeric data.
As an example, 1:AN means sort the first input field numerically in ascending order. The difference between the numeric and string sorting can be seen by considering the following data 2 1 10 If sorted (ascending) numerically, we get: 1 2 10 but if using string sorting, we get: 1 10 2
-rh | No | Treat the first input record as a CSV header containing the column names and do not sort it, but place it as the first record in the sorted output.

The following example sorts the names.csv file into descending order of sex and ascending order of surname:
csvfix.exe sort -f 3:D,2 data/names.csv
which produces:
"Charles","Dickens","M"
"Herman","Melville","M"
"Flann","O'Brien","M"
"Oscar","Wilde","M"
"Jane","Austen","F"
"George","Elliot","F"
"Virginia","Woolf","F"

Created with the Personal Edition of HelpNDoc: Create HTML Help, DOC, PDF and print manuals from 1 single source

####