LinuxCommandLibrary

csv2tsv

Convert CSV files to TSV files

TLDR

Convert from CSV to TSV

$ csv2tsv [path/to/input_csv1 path/to/input_csv2 ...] > [path/to/output_tsv]
copy

Convert field delimiter separated CSV to TSV
$ csv2tsv -c'[field_delimiter]' [path/to/input_csv]
copy

Convert semicolon separated CSV to TSV
$ csv2tsv -c';' [path/to/input_csv]
copy

SYNOPSIS

csv2tsv < input.csv > output.tsv

DESCRIPTION

The `csv2tsv` command is a simple utility used to convert Comma Separated Values (CSV) files to Tab Separated Values (TSV) files. This is useful when you need to work with data in a format that's easier to parse with tools that expect tab-delimited data.

Essentially, it replaces all commas within a CSV file with tab characters. The command reads from standard input and writes to standard output, allowing it to be easily piped with other command-line tools. It does not offer advanced options for handling quoted fields, escaping special characters, or customizing the delimiter beyond simply changing commas to tabs. Because of this simple, single-purpose design, it may not be suitable for complex CSV files that include commas within quoted strings. It is most effective for simple CSV files where the data elements do not contain embedded commas.

CAVEATS

The command doesn't handle quoted fields, so CSV files with commas inside quotes will not be converted correctly. It is a basic conversion tool suitable only for simple CSV files.

USAGE EXAMPLE

To convert a CSV file named 'data.csv' to a TSV file named 'data.tsv', you would use the following command: csv2tsv < data.csv > data.tsv

This will read the content of data.csv, replace the commas with tabs, and write the result to data.tsv.

PIPING

You can use the pipe symbol '|' to directly pass the output of one command to csv2tsv.

For example, if you had a command 'generate_csv' that outputs a CSV file to standard output, you could convert it to TSV and save it:generate_csv | csv2tsv > output.tsv

SEE ALSO

tsv2csv(1), awk(1), sed(1)

Copied to clipboard