W3cubDocs

/Nushell

insert for filters

Insert a new column, using an expression or closure to create each row's values.

Signature

> insert {flags} (field) (new value)

Parameters

  • field: the name of the column to insert
  • new value: the new value to give the cell(s)

Input/output types:

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

Examples

Insert a new entry into a single record

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

Insert a new column into a table, populating all rows

> [[project, lang]; ['Nushell', 'Rust']] |inserttype'shell'
╭───┬─────────┬──────┬───────╮
# │ project │ lang │ type  │
├───┼─────────┼──────┼───────┤
0NushellRustshell
╰───┴─────────┴──────┴───────╯

Insert a column with values equal to their row index, plus the value of 'foo' in each row

> [[foo]; [7] [8] [9]] |enumerate|insertbar {|e| $e.item.foo+$e.index } |flatten
╭───┬─────┬─────╮
# │ foo │ bar │
├───┼─────┼─────┤
077
189
2911
╰───┴─────┴─────╯

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