update
for filters
Update an existing column to have a new value.
Signature
> update (field) (replacement value)
Parameters
field
: the name of the column to updatereplacement value
: the new value to give the cell(s), or a closure to create the value
Examples
Update a column value
> {'name': 'nu', 'stars': 5} | update name 'Nushell'
╭───────┬─────────╮
│ name │ Nushell │
│ stars │ 5 │
╰───────┴─────────╯
Use in closure form for more involved updating logic
> [[count fruit]; [1 'apple']] | enumerate | update item.count {|e| ($e.item.fruit | str length) + $e.index } | get item
╭───┬───────┬───────╮
│ # │ count │ fruit │
├───┼───────┼───────┤
│ 0 │ 5 │ apple │
╰───┴───────┴───────╯
Alter each value in the 'authors' column to use a single string instead of a list
> [[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 │
╰───┴─────────┴──────────────────╯