W3cubDocs

/Nushell

sort-by for filters

Sort by the given columns, in increasing order.

Signature

> sort-by {flags} ...rest

Flags

  • --reverse, -r: Sort in reverse order
  • --ignore-case, -i: Sort string-based columns case-insensitively
  • --natural, -n: Sort alphanumeric string-based columns naturally (1, 9, 10, 99, 100, ...)

Parameters

  • ...rest: the column(s) to sort by

Input/output types:

input output
list<any> list<any>
table table

Examples

Sort files by modified date

>ls|sort-bymodified

Sort files by name (case-insensitive)

>ls|sort-byname-i

Sort a table by a column (reversed order)

> [[fruitcount]; [apple9] [pear3] [orange7]] |sort-byfruit-r
╭───┬────────┬───────╮
# │ fruit  │ count │
├───┼────────┼───────┤
0pear3
1orange7
2apple9
╰───┴────────┴───────╯

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