csvkit(1)
A suite of command-line tools for converting, querying, and analyzing CSV files.
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
| Flag | What it does |
|---|---|
-d, --delimiter | Specify the delimiter character (default: comma) |
-t, --tabs | Specify that the input uses tabs as delimiters |
-q, --quotechar | Specify the character used to quote fields (default: double quote) |
-H, --no-header-row | Specify that the input has no header row |
-h, --help | Display help message with available options |
--sniff-limit | Set the maximum number of bytes to sample for format detection |
--encoding | Specify the encoding of the input file (default: UTF-8) |
-v, --version | Display the version number |
Examples
Extract columns 1, 3, and 5 from a CSV file
csvcut -c 1,3,5 data.csvSelect specific columns by name and display in pretty-printed format
csvcut -c name,email,phone data.csv | csvlookFilter rows where the 'status' column matches 'active'
csvgrep -c status -m 'active' data.csvDisplay summary statistics (count, min, max, mean, median) for all columns
csvstat data.csvSort the CSV file by age column in reverse order
csvsort -c age -r data.csvJoin two CSV files on the 'id' column
csvjoin -c id left.csv right.csvDisplay the first 20 rows of a CSV in aligned table format
csvlook data.csv | head -20Filter rows where name starts with J, then select name and age columns
cat data.csv | csvgrep -c name -r '^J' | csvcut -c name,age