sort

May 31, 2026 · View on GitHub

Sorts CSV data in lexicographical, natural, numerical, reverse, unique or random (with optional seed) order (Also see extsort & sortcheck commands).

Table of Contents | Source: src/cmd/sort.rs | 🤯🚀👆🎲

Description | Usage | Sort Options | Random Sorting Options | Common Options

Description

Sorts CSV data in lexicographical, natural, numerical, reverse, unique or random order.

Note that this requires reading all of the CSV data into memory. If you need to sort a large file that may not fit into memory, use the extsort command instead.

For examples, see https://github.com/dathere/qsv/blob/master/tests/test_sort.rs. See also https://github.com/dathere/qsv/wiki/Transform-and-Reshape#sort

Usage

qsv sort [options] [<input>]
qsv sort --help

Sort Options

     Option     TypeDescriptionDefault
 ‑s,
‑‑select 
stringSelect a subset of columns to sort. See 'qsv select --help' for the format details.
 ‑N,
‑‑numeric 
flagCompare according to string numerical value
 ‑‑natural flagCompare strings using natural sort order (treats numbers within strings as actual numbers, e.g. "data1.txt", "data2.txt", "data10.txt", as opposed to "data1.txt", "data10.txt", "data2.txt" when sorting lexicographically) https://en.wikipedia.org/wiki/Natural_sort_order When combined with --numeric, --natural takes precedence.
 ‑R,
‑‑reverse 
flagReverse order
 ‑i,
‑‑ignore‑case 
flagCompare strings disregarding case. Has no effect when numeric comparison is selected (i.e. when --numeric is used without --natural).
 ‑u,
‑‑unique 
flagWhen set, identical consecutive lines will be dropped to keep only one line per sorted value. The same comparison mode used to sort the input is also used here, so unique-equality always agrees with the sort.

Random Sorting Options

     Option     TypeDescriptionDefault
 ‑‑random flagRandomize (scramble) the data by row. When set, the numeric, natural, and ignore-case comparison flags still apply to unique-filtering (if --unique is also set). The reverse flag has no effect on unique-filter equality and is ignored for the shuffle itself.
 ‑‑seed integerRandom Number Generator (RNG) seed to use if --random is set
 ‑‑rng stringThe RNG algorithm to use if --random is set.standard
 ‑j,
‑‑jobs 
integerThe number of jobs to run in parallel. When not set, the number of jobs is set to the number of CPUs detected.
 ‑‑faster flagWhen set, the sort will be faster. This is done by using a faster sorting algorithm that is not "stable" (i.e. the order of identical values is not guaranteed to be preserved). It has the added side benefit that the sort will also be in-place (i.e. does not allocate), which is useful for sorting large files that will otherwise NOT fit in memory using the default allocating stable sort.

Common Options

     Option     TypeDescriptionDefault
 ‑h,
‑‑help 
flagDisplay this message
 ‑o,
‑‑output 
stringWrite output to instead of stdout.
 ‑n,
‑‑no‑headers 
flagWhen set, the first row will not be interpreted as headers. Namely, it will be sorted with the rest of the rows. Otherwise, the first row will always appear as the header row in the output.
 ‑d,
‑‑delimiter 
stringThe field delimiter for reading CSV data. Must be a single character. (default: ,)
 ‑‑memcheck flagCheck if there is enough memory to load the entire CSV into memory using CONSERVATIVE heuristics. Ignored if --random or --faster is set.

Source: src/cmd/sort.rs | Table of Contents | README