LinuxCommandLibrary

in2csv

Convert various file formats to CSV

TLDR

Convert an XLS file to CSV

$ in2csv [data.xls]
copy

Convert a DBF file to a CSV file
$ in2csv [data.dbf] > [data.csv]
copy

Convert a specific sheet from an XLSX file to CSV
$ in2csv --sheet=[sheet_name] [data.xlsx]
copy

Pipe a JSON file to in2csv
$ cat [data.json] | in2csv [[-f|--format]] json > [data.csv]
copy

SYNOPSIS

in2csv [options] input_file

PARAMETERS

-f, --format format
    Specify the input format (e.g., json, xls, xlsx, fixed). Auto-detection is attempted if not specified.

-e, --encoding encoding
    Specify the character encoding of the input file (e.g., utf-8, latin1). Defaults to UTF-8.

-d, --delimiter delimiter
    Specify the delimiter character to use in the CSV output. Defaults to comma (,).

-L, --linenumbers
    Insert a column of line numbers at the beginning of the output.

-S, --sheet sheet
    When converting Excel files, specify the sheet number or name to convert. Defaults to the first sheet.

--key key
    When converting JSON, specify the key containing list of records.

-H, --headers
    Indicate that the first row of the input file contains column headers (only relevant for fixed-width files without header line).

--names column_names
    Specify a comma-separated list of column names for fixed-width files without a header row.

-w, --width column_widths
    Specify a comma-separated list of column widths for fixed-width files.

--skip-lines number_of_lines
    Skip the first N lines of the input.

-I, --no-inference
    Disable type inference when converting from formats like JSON.

--version
    Show program's version number and exit

-h, --help
    Show help message and exit

DESCRIPTION

The in2csv command is a powerful command-line utility designed to convert various structured data formats into CSV (Comma Separated Values) format.
It is particularly useful for processing data that is not already in CSV, such as JSON, Excel spreadsheets (xls, xlsx), and fixed-width files.
This conversion process allows users to easily import and manipulate data with tools that readily support CSV, including spreadsheet applications, databases, and data analysis software like Pandas.
The command offers flexibility with options for specifying input files, character encoding, delimiter characters, and other format settings to accommodate diverse data sources and cleaning needs. The in2csv command comes with the `csvkit` tools.

TYPE INFERENCE

in2csv tries to determine the datatypes of each column when converting data from formats like JSON. This behavior can be disabled using the --no-inference flag.

SEE ALSO

csvcut(1), csvstat(1), csvlook(1), csvgrep(1)

Copied to clipboard