LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid