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

update for filters

Update an existing column to have a new value.

Signature

> update {flags} (field) (replacement value)

Parameters

  • field: The name of the column to update.
  • replacement value: The new value to give the cell(s), or a closure to create the value.

Input/output types:

inputoutput
list<any>list<any>
recordrecord
tabletable

Examples

Update a column value

> {'name': 'nu', 'stars': 5} | update name 'Nushell'
╭───────┬─────────╮
│ name  │ Nushell │
│ stars │ 5       │
╰───────┴─────────╯

Use a closure to alter each value in the 'authors' column to a single string

> [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors {|row| $row.authors | str join ',' }
╭───┬─────────┬──────────────────╮
│ # │ project │     authors      │
├───┼─────────┼──────────────────┤
│ 0 │ nu      │ Andrés,JT,Yehuda │
╰───┴─────────┴──────────────────╯

Implicitly use the $in value in a closure to update 'authors'

> [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { str join ',' }
╭───┬─────────┬──────────────────╮
│ # │ project │     authors      │
├───┼─────────┼──────────────────┤
│ 0 │ nu      │ Andrés,JT,Yehuda │
╰───┴─────────┴──────────────────╯

Update a value at an index in a list

> [1 2 3] | update 1 4
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 4 │
│ 2 │ 3 │
╰───┴───╯

Use a closure to compute a new value at an index

> [1 2 3] | update 1 {|i| $i + 2 }
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 4 │
│ 2 │ 3 │
╰───┴───╯

Notes

When updating a column, the closure will be run for each row, and the current row will be passed as the first argument. Referencing $in inside the closure will provide the value at the column for the current row.

When updating a specific index, the closure will instead be run once. The first argument to the closure and the $in value will both be the current value at the index.

Subcommands:

namedescriptiontype
update cellsUpdate the table cells.built-in