LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

in2csv

converts tabular data from various formats to CSV

TLDR

Convert Excel to CSV
$ in2csv [data.xlsx] > [output.csv]
copy
List sheet names in an Excel file
$ in2csv -n [data.xlsx]
copy
Convert a specific sheet
$ in2csv --sheet [Sheet1] [data.xlsx] > [output.csv]
copy
Write every sheet to its own CSV file
$ in2csv --write-sheets - --use-sheet-names [data.xlsx]
copy
Convert JSON from stdin (format must be given for piped input)
$ curl [https://api.example.com/items] | in2csv -f json > [output.csv]
copy
Convert JSON nested under a top-level key
$ in2csv -k [results] [data.json]
copy
Convert fixed-width data using a schema file
$ in2csv -f fixed -s [schema.csv] [data.txt]
copy
Convert a DBF file
$ in2csv [data.dbf] > [output.csv]
copy

SYNOPSIS

in2csv [options] [file]

DESCRIPTION

in2csv converts tabular data from various formats to CSV. It's part of the csvkit toolkit for working with CSV files.The tool handles Excel (XLS, XLSX), JSON, newline-delimited JSON, GeoJSON, DBF, fixed-width and CSV input. Run on a CSV file, it standardizes quoting and line endings. The output can be piped to other csvkit tools for analysis.

PARAMETERS

-f, --format FORMAT

Input format: csv, dbf, fixed, geojson, json, ndjson, xls, xlsx. Inferred from the file extension if omitted.
-s, --schema SCHEMA
CSV schema file (column,start,length) for fixed-width input.
-k, --key KEY
Top-level JSON key containing the list of objects to convert.
-n, --names
Display sheet names from the Excel file.
--sheet NAME
Excel sheet to convert.
--write-sheets NAMES
Comma-separated sheet names (or - for all) to write to separate files.
--use-sheet-names
Name files after sheets when using --write-sheets.
--encoding-xls ENCODING
Encoding of the input XLS file.
-e, --encoding ENCODING
Encoding of the input file.
-H, --no-header-row
Input has no header row; columns are named a, b, c...
-K, --skip-lines N
Skip N lines at the start of the input.
-I, --no-inference
Disable type inference when parsing CSV input.
-y, --snifflimit BYTES
Limit CSV dialect sniffing; 0 disables it, -1 sniffs the whole file.
-h, --help
Display help information.

CAVEATS

Part of csvkit (Python). Large files may be slow. When reading from stdin, -f is required. Numbers from XLS files may gain decimals that the equivalent XLSX would not have. Unnamed header columns are given generated names.

HISTORY

in2csv is part of csvkit, created by Christopher Groskopf in 2011 for journalists and data analysts, and now maintained by the wireservice organization.

SEE ALSO

csvcut(1), csvlook(1), csvstat(1), csvsql(1), csvjson(1)

RESOURCES

Copied to clipboard
Kai