$linuxjunkies
>

csvkit(1)

A suite of command-line tools for converting, querying, and analyzing CSV files.

UbuntuDebianFedoraArch

Synopsis

csvkit [COMMAND] [OPTIONS] [FILE]...

Description

csvkit is a collection of utilities for working with CSV data: csvcut for selecting columns, csvgrep for filtering rows, csvstat for statistics, csvsort for sorting, csvjoin for joining tables, and csvlook for pretty-printing. Each tool is a separate command that reads CSV input and performs a specific operation.

By default, csvkit uses comma as the delimiter and handles quoted fields correctly. It supports various input/output formats including JSON, SQL, and fixed-width text. The tools work well in Unix pipelines and handle large files efficiently.

Common options

FlagWhat it does
-d, --delimiterSpecify the delimiter character (default: comma)
-t, --tabsSpecify that the input uses tabs as delimiters
-q, --quotecharSpecify the character used to quote fields (default: double quote)
-H, --no-header-rowSpecify that the input has no header row
-h, --helpDisplay help message with available options
--sniff-limitSet the maximum number of bytes to sample for format detection
--encodingSpecify the encoding of the input file (default: UTF-8)
-v, --versionDisplay the version number

Examples

Extract columns 1, 3, and 5 from a CSV file

csvcut -c 1,3,5 data.csv

Select specific columns by name and display in pretty-printed format

csvcut -c name,email,phone data.csv | csvlook

Filter rows where the 'status' column matches 'active'

csvgrep -c status -m 'active' data.csv

Display summary statistics (count, min, max, mean, median) for all columns

csvstat data.csv

Sort the CSV file by age column in reverse order

csvsort -c age -r data.csv

Join two CSV files on the 'id' column

csvjoin -c id left.csv right.csv

Display the first 20 rows of a CSV in aligned table format

csvlook data.csv | head -20

Filter rows where name starts with J, then select name and age columns

cat data.csv | csvgrep -c name -r '^J' | csvcut -c name,age

Related commands