Skip to main content

## file_split

The file_split command splits a CSV input stream into a number of files based on the values of specified fields in the CSV input stream. All the CSV records with the same values for those fields will be placed in the same file. By default, the created files are numbered, but you can also generate files based on the contents of the fields used to perform the split. Unlike most other CSVfix commands, this command does not write anything to standard output, or to any file specified by the -o flag.
Note that any existing files will be overwritten by this command, without warning. Use the -fd flag to locate the output files, and the -fp and -fx flags to name them.
See also: find, remove

Flag | Req'd? | Description
-f fields | Yes | Comma-separated list of filed indexes on which to base the split.
-fd dir | No | Specifies the directory in which to place the results of the split. Defaults to the current directory.
-fp prefix | No | Specifies the prefix to use when constructing file names. Default is file_
-fx ext | No | Specifies the extension to use when constructing file names. The default is csv
-ufn | No | Use the contents of the field(s) specified by the -f flag to generate file names. No check is made that the fields contain valid file name components, and the command will fail if they do not.

The following example splits the cities.csv file based on the second field, which contains the country code.
csvfix file_split -f 2 data/cities.csv
This produces the following files, each of which contains the cities for a particular country:
file_0001.csv
file_0002.csv
file_0003.csv
file_0004.csv
file_0005.csv
file_0006.csv
With the same data, the following example:
csvfix file_split -f 2 -ufn data/cities.csv
uses the country code values to generate the file names, producing:
file_DE.csv
file_FR.csv
file_GB.csv
file_GR.csv
file_IT.csv
file_NL.csv
Here, file_DE.csv will contain German cities, file_FR.csv French cities, and so on.

Created with the Personal Edition of HelpNDoc: Full-featured multi-format Help generator

####