sort for filters

Sort in increasing order.

Signature

> sort --reverse --ignore-case --values --natural

Parameters

  • --reverse (-r): Sort in reverse order
  • --ignore-case (-i): Sort string-based data case-insensitively
  • --values (-v): If input is a single record, sort the record by values; ignored if input is not a single record
  • --natural (-n): Sort alphanumeric string-based values naturally (1, 9, 10, 99, 100, ...)

Input/output types:

inputoutput
list<any>list<any>
recordrecord

Examples

sort the list by increasing value

> [2 0 1] | sort
╭───┬───╮
│ 00 │
│ 11 │
│ 22 │
╰───┴───╯

sort the list by decreasing value

> [2 0 1] | sort -r
╭───┬───╮
│ 02 │
│ 11 │
│ 20 │
╰───┴───╯

sort a list of strings

> [betty amy sarah] | sort
╭───┬───────╮
│ 0 │ amy   │
│ 1 │ betty │
│ 2 │ sarah │
╰───┴───────╯

sort a list of strings in reverse

> [betty amy sarah] | sort -r
╭───┬───────╮
│ 0 │ sarah │
│ 1 │ betty │
│ 2 │ amy   │
╰───┴───────╯

Sort strings (case-insensitive)

> [airplane Truck Car] | sort -i
╭───┬──────────╮
│ 0 │ airplane │
│ 1 │ Car      │
│ 2 │ Truck    │
╰───┴──────────╯

Sort strings (reversed case-insensitive)

> [airplane Truck Car] | sort -i -r
╭───┬──────────╮
│ 0 │ Truck    │
│ 1 │ Car      │
│ 2 │ airplane │
╰───┴──────────╯

Sort record by key (case-insensitive)

> {b: 3, a: 4} | sort
╭───┬───╮
│ a │ 4 │
│ b │ 3 │
╰───┴───╯

Sort record by value

> {b: 4, a: 3, c:1} | sort -v
╭───┬───╮
│ c │ 1 │
│ a │ 3 │
│ b │ 4 │
╰───┴───╯