W3cubDocs

/Nushell

split list for filters

Split a list into multiple lists using a separator.

Signature

> split list {flags} (separator)

Flags

  • --regex, -r: separator is a regular expression, matching values that can be coerced into a string

Parameters

  • separator: the value that denotes what separates the list

Input/output types:

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

Examples

Split a list of chars into two lists

> [a, b, c, d, e, f, g] |split listd
╭───┬───────────╮
0╭───┬───╮
0a
1b
2c
╰───┴───╯
1╭───┬───╮
0e
1f
2g
╰───┴───╯
╰───┴───────────╯

Split a list of lists into two lists of lists

> [[1,2], [2,3], [3,4]] |split list [2,3]
╭───┬───────────────────╮
0╭───┬───────────╮
0╭───┬───╮
01
12
╰───┴───╯
╰───┴───────────╯
1╭───┬───────────╮
0╭───┬───╮
03
14
╰───┴───╯
╰───┴───────────╯
╰───┴───────────────────╯

Split a list of chars into two lists

> [a, b, c, d, a, e, f, g] |split lista
╭───┬───────────╮
0╭───┬───╮
0b
1c
2d
╰───┴───╯
1╭───┬───╮
0e
1f
2g
╰───┴───╯
╰───┴───────────╯

Split a list of chars into lists based on multiple characters

> [a, b, c, d, a, e, f, g] |split list-r'(b|e)'
╭───┬───────────╮
0╭───┬───╮
0a
╰───┴───╯
1╭───┬───╮
0c
1d
2a
╰───┴───╯
2╭───┬───╮
0f
1g
╰───┴───╯
╰───┴───────────╯

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