W3cubDocs

/Nushell

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:

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

Examples

Update a column value

> {'name':'nu', 'stars':5} |updatename'Nushell'
╭───────┬─────────╮
nameNushell
stars5
╰───────┴─────────╯

Use in closure form for more involved updating logic

> [[countfruit]; [1'apple']] |enumerate|updateitem.count {|e| ($e.item.fruit|str length) +$e.index } |getitem
╭───┬───────┬───────╮
# │ count │ fruit │
├───┼───────┼───────┤
05apple
╰───┴───────┴───────╯

Alter each value in the 'authors' column to use a single string instead of a list

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

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

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

Subcommands:

name type usage
update cells Builtin Update the table cells.

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