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 
╰───┴─────────┴──────────────────╯

You can also use a simple command to update 'authors' to a single string

> [[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 
╰───┴───╯

Subcommands:

nametypeusage
update cellsBuiltinUpdate the table cells.