W3cubDocs

/Nushell

sort for filters

Sort in increasing order.

Signature

> sort {flags}

Flags

  • --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:

input output
list<any> list<any>
record record

Examples

sort the list by increasing value

> [201] |sort
╭───┬───╮
00
11
22
╰───┴───╯

sort the list by decreasing value

> [201] |sort-r
╭───┬───╮
02
11
20
╰───┴───╯

sort a list of strings

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

sort a list of strings in reverse

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

Sort strings (case-insensitive)

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

Sort strings (reversed case-insensitive)

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

Sort record by key (case-insensitive)

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

Sort record by value

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

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/sort.html