±colnames, ±c
Defining whether the csv file has a header line containing the column names
Description
+c Defines whether the first line of the CSV file will be interpreted as containing the column names.-c Sets or inhibits the output if a column header line when writing a CSV file.
If the input file does not contain column names (
However, these columns can also be given a name for output, e.g. for the third column using
Per default csvfox is assuming that the first row contains column names in all files (+
Pattern
±c=truthvalue
±colnames=truthvalue
Usage Examples
In the following examples, the column header line will have a colored background. So you can easily see which CSV tables have column names, and which have none.
CSV Table with column Names (Default Mode)
- csvfox inputfile.csv
- csvfox inputfile.csv +colnames=Yes
- Assumes that the CSV file to read (inputfile.csv) has column names in the first row. This is default behaviour:
inputfile.csv Season Green Car Days spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
CSV Table without Column Names
- csvfox inputfile.csv +c=N
- Assumes that the CSV file to read (inputfile.csv) does not have column names in the first row.
When there is in fact no header line, this behaviour is correct:
inputfile.csv spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90 However, this will also misinterpret an existing header line to be the first data row:
inputfile.csv Season Green Car Days spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
Removing the Column Names for Output
- csvfox inputfile.csv +c=yes -c=N outputfile.csv
- Assumes that the CSV file to read (inputfile.csv) has column names in the first row, while the CSV file to write (outputfile.csv) will have them omitted.
In other words, this removes the header line with the column names.inputfile.csv Season Green Car Days spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
This might be necessary if the target application cannot work with a column header line, or when the output data rows are to be appended to an existing CSV file with identical structure.outputfile.csv spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
Introducing Column Names for Output
- csvfox inputfile.csv +c=N -c=Y outputfile.csv
- Assumes that the CSV file to read (inputfile.csv) has no column names in the first row, while the CSV file to write (outputfile.csv) will have them.
In other words, this invents a header line with empty column names.inputfile.csv spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
In this case, the missing column names should be filled in next, using ±rename. Example:outputfile.csv spring flowers bicycle 91 summer fruits cabriolet 92 autumn colorful leaves limousine 92 winter snowy twigs sled 90
-rename[1]-[4]=[Season],[Green],[Car],[Days]