update
for filters> update {flags} (field) (replacement value)
field
: the name of the column to updatereplacement value
: the new value to give the cell(s), or a closure to create the valueinput | output |
---|---|
list<any> | list<any> |
record | record |
table | table |
Update a column value
> {'name':'nu', 'stars':5} |updatename'Nushell'
╭───────┬─────────╮
│name│Nushell│
│stars│5│
╰───────┴─────────╯
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 │
├───┼───────┼───────┤
│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']]] |updateauthors {|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']]] |updateauthors {|| str join','}
╭───┬─────────┬──────────────────╮
│# │ project │ authors │
├───┼─────────┼──────────────────┤
│0│nu│Andrés,JT,Yehuda│
╰───┴─────────┴──────────────────╯
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