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
    • Shells
    • Strings
    • System
    • Viewers

get for filters

Extract data using a cell path.

Command Type

built-in

Signature

> get {flags} ...rest

Flags

  • --optional, -o: Make all cell path members optional (returns null for missing values).
  • --ignore-case: Make all cell path members case insensitive.

Parameters

  • ...rest: The cell paths to the data.

Input/output types:

inputoutput
list<any>any
tableany
recordany
nothingnothing

Examples

Get an item from a list.

> [0 1 2] | get 1
1

Return the input unchanged if no cell path is given.

> [0 1 2] | get
╭───┬───╮
│ 0 │ 0 │
│ 1 │ 1 │
│ 2 │ 2 │
╰───┴───╯

Get a column from a table.

> [{A: A0}] | get A
╭───┬────╮
│ 0 │ A0 │
╰───┴────╯

Get a column from a table where some rows don't have that column, using optional cell-path syntax.

> [{A: A0, B: B0}, {B: B1}, {A: A2, B: B2}] | get A?
╭───┬────╮
│ 0 │ A0 │
│ 1 │    │
│ 2 │ A2 │
╰───┴────╯

Get a column from a table where some rows don't have that column, using the optional flag.

> [{A: A0, B: B0}, {B: B1}, {A: A2, B: B2}] | get -o A
╭───┬────╮
│ 0 │ A0 │
│ 1 │    │
│ 2 │ A2 │
╰───┴────╯

Get a cell from a table.

> [{A: A0}] | get 0.A
A0

Get multiple columns from a table using a spread list.

> [[a b c]; [1 2 3]] | get ...[a c]
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ 3 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

Get columns from a table using a spread variable.

> let cols = [a b]; [{a: 1, b: 2, c: 3}] | get ...$cols
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ 2 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

A spread always produces a list of values, even when it holds a single path.

> let cols = [a]; [{a: 1, b: 2}] | get ...$cols
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

An empty spread produces an empty list.

> let cols = []; [{a: 1, b: 2}] | get ...$cols
╭────────────╮
│ empty list │
╰────────────╯

Spread nested paths as cell-path values, since spread strings are single column names.

> let paths = [$.a.b]; {a: {b: 1}} | get ...$paths
╭───┬───╮
│ 0 │ 1 │
╰───┴───╯

Extract the name of the 3rd record in a list (same as ls | $in.name.2).

> ls | get name.2

Extract the name of the 3rd record in a list.

> ls | get 2.name

Getting environment variables in a case insensitive way, using case insensitive cell-path syntax.

> $env | get home! path!

Getting environment variables in a case insensitive way, using the '--ignore-case' flag.

> $env | get --ignore-case home path

Getting Path in a case sensitive way, won't work for 'PATH'.

> $env | get Path

Notes

This is equivalent to using the cell path access syntax: $env.OS is the same as $env | get OS.

With no cell path, the input is returned unchanged. With one cell path and no spread, this returns the value at that path. If multiple cell paths are given, or any argument is a spread (...$paths), this produces a list with one value per path, so the result has the same shape however many paths the spread holds, and an empty spread produces an empty list.

Strings in a spread are single column names: ...[a.b] looks for a column named a.b. To spread nested paths, use cell-path values such as $.a.b, or convert with into cell-path.