LinuxCommandLibrary

csvsort

Type-aware CSV file sorter

TLDR

Sort by column

$ csvsort -c [column] [data.csv]
copy
Sort descending
$ csvsort -r -c [column] [data.csv]
copy
Sort by multiple columns
$ csvsort -c [col1,col2] [data.csv]
copy
Sort numerically
$ csvsort -c [amount] [data.csv]
copy
Sort with no header
$ csvsort -H -c [1] [data.csv]
copy
Read from stdin
$ cat [data.csv] | csvsort -c [name]
copy

SYNOPSIS

csvsort [options] file

DESCRIPTION

csvsort sorts CSV files by one or more columns. Part of csvkit, it properly handles CSV quoting and data types, detecting numeric and date values for appropriate sorting.
The tool maintains CSV structure during sorting, preserving headers and quoted fields correctly.

PARAMETERS

-c columns

Column(s) to sort by.
-r, --reverse
Sort in descending order.
-H, --no-header-row
Input has no header.
-d char
Field delimiter.
-q char
Quote character.
-e encoding
Input encoding.
-y n
Rows to sniff for type.

CAVEATS

Requires loading entire file into memory. Part of csvkit, needs Python. Type detection may not always match expectations. Large files can be slow.

HISTORY

csvsort is part of csvkit, created by Christopher Groskopf in 2011. The tool provides type-aware sorting that the Unix sort command cannot easily achieve with CSV data.

SEE ALSO

csvcut(1), csvlook(1), sort(1), csvstat(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community