Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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:

inputoutput
list<any>list<any>
recordtable

Examples

flatten a table

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

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 | get meal

restrict the flattening by passing column names

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

Flatten inner table

> { a: b, d: [ 1 2 3 4 ], e: [ 4 3 ] } | flatten d --all
╭───┬───┬───┬───────────╮
│ # │ a │ d │     e     │
├───┼───┼───┼───────────┤
│ 0 │ b │ 1 │ ╭───┬───╮ │
│   │   │   │ │ 0 │ 4 │ │
│   │   │   │ │ 1 │ 3 │ │
│   │   │   │ ╰───┴───╯ │
│ 1 │ b │ 2 │ ╭───┬───╮ │
│   │   │   │ │ 0 │ 4 │ │
│   │   │   │ │ 1 │ 3 │ │
│   │   │   │ ╰───┴───╯ │
│ 2 │ b │ 3 │ ╭───┬───╮ │
│   │   │   │ │ 0 │ 4 │ │
│   │   │   │ │ 1 │ 3 │ │
│   │   │   │ ╰───┴───╯ │
│ 3 │ b │ 4 │ ╭───┬───╮ │
│   │   │   │ │ 0 │ 4 │ │
│   │   │   │ │ 1 │ 3 │ │
│   │   │   │ ╰───┴───╯ │
╰───┴───┴───┴───────────╯