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 |
|---|---|
| record | record |
| table | table |
| list<any> | list<any> |
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:
| name | description | type |
|---|---|---|
update cells | Update the table cells. | built-in |