![]() |
![]()
| ![]() |
![]()
NAMEcsvclean - csvclean Documentation DESCRIPTIONReports and fixes common errors in a CSV file. Checks
TIP: Enable all checks with --enable-all-checks
(-a).
Fixes
id,address,country 1,1 Main St Springfield,US 2,123 Acadia Avenue London,GB Use --join-short-rows to attempt to correct the errors by merging short rows into a single row: id,address,country 1,"1 Main St Springfield",US 2,"123 Acadia Avenue London",GB To change the string used to join the lines, use --separator. For example, with --separator ", ": id,address,country 1,"1 Main St, Springfield",US 2,"123 Acadia Avenue, London",GB
id,name,country 1,Alice 2,Bob,CA You can add the missing delimiters with --fill-short-rows: id,name,country 1,Alice, 2,Bob,CA TIP: csvcut without options also adds missing
delimiters!
To change the value used to fill short rows, use --fillvalue. For example, with --fillvalue "US": id,name,country 1,Alice,US 2,Bob,CA SEE ALSO: --header-normalize-space under Usage.
NOTE: Every csvkit tool does the following:
Outputcsvclean attempts to make the selected fixes. Then:
Usageusage: csvclean [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b] See also: Arguments common to all tools. EXAMPLESTest a file with data rows that are shorter and longer than the header row: $ csvclean examples/bad.csv 2> errors.csv column_a,column_b,column_c 0,mixed types.... uh oh,17 $ cat errors.csv line_number,msg,column_a,column_b,column_c 1,"Expected 3 columns, found 4 columns",1,27,,I'm too long! 2,"Expected 3 columns, found 2 columns",,I'm too short! NOTE: If any data rows are longer than the header row, you need
to add columns manually: for example, by adding one or more delimiters
(,) to the end of the header row. csvclean can't do this,
because it is designed to work with standard input, and correcting an error at
the start of the CSV data based on an observation later in the CSV data would
require holding all the CSV data in memory – which is not an option for
large files.
Test a file with empty columns: $ csvclean --empty-columns examples/test_empty_columns.csv 2> errors.csv a,b,c,, a,,,, ,,c,, ,,,, $ cat errors.csv line_number,msg,a,b,c,, 1,"Empty columns named 'b', '', ''! Try: csvcut -C 2,4,5",,,,, Use csvcut to exclude the empty columns: $ csvcut -C 2,4,5 examples/test_empty_columns.csv a,c a, ,c , To change the line ending from line feed (LF or \n) to carriage return and line feed (CRLF or \r\n) use: csvformat -M $'\r\n' examples/dummy.csv AUTHORChristopher Groskopf and contributors COPYRIGHT2016, Christopher Groskopf and James McKinney
|