W3cubDocs

/Nushell

flatten for filters

Flatten the table.

Signature

> flatten {flags} ...rest

Flags

  • --all, -a: flatten inner table one level out

Parameters

  • ...rest: optionally flatten data by column

Input/output types:

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

Examples

flatten a table

> [[N, u, s, h, e, l, l]] |flatten
╭───┬───╮
0N
1u
2s
3h
4e
5l
6l
╰───┴───╯

flatten a table, get the first item

> [[N, u, s, h, e, l, l]] |flatten|first

flatten a column having a nested table

> [[origin, people]; [Ecuador, ([[name, meal]; ['Andres', 'arepa']])]] |flatten--all|getmeal

restrict the flattening by passing column names

> [[origin, crate, versions]; [World, ([[name]; ['nu-cli']]), ['0.21', '0.22']]] |flattenversions--all|last|getversions

Flatten inner table

> { a:b, d: [ 1234 ],  e: [ 43  ] } |flattend--all
╭───┬───┬───┬───────────╮
# │ a │ d │     e     │
├───┼───┼───┼───────────┤
0b1╭───┬───╮
04
13
╰───┴───╯
1b2╭───┬───╮
04
13
╰───┴───╯
2b3╭───┬───╮
04
13
╰───┴───╯
3b4╭───┬───╮
04
13
╰───┴───╯
╰───┴───┴───┴───────────╯

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