Skip to content

Can i specify the sort rule when sort an table #12605

@malongshuai

Description

@malongshuai

Question

for example, i want to sort the result of ls command by the filename length.

~> ls
╭───┬─────────────────────┬──────┬─────────┬──────────────╮
│ # │        name         │ type │  size   │   modified   │
├───┼─────────────────────┼──────┼─────────┼──────────────┤
│ 0 │ dump.rdb            │ file │   975 B │ 3 weeks ago  │
│ 1 │ redis-stable        │ dir  │ 4.0 KiB │ 3 months ago │
│ 2 │ redis-stable.tar.gz │ file │ 3.3 MiB │ 3 months ago │
╰───┴─────────────────────┴──────┴─────────┴──────────────╯

i checked the document: sort-by(https://www.nushell.sh/commands/docs/sort-by.html), i think it can accept a closure to sort by any rule. like this:

ls | sort-by {|row| $row.name | length}

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprecated:questionQuestions should be redirected to GitHub discussions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions