W3cubDocs

/Nushell

take for filters

Take only the first n elements of a list, or the first n bytes of a binary value.

Signature

> take {flags} (n)

Parameters

  • n: starting from the front, the number of elements to return

Input/output types:

input output
binary binary
list<any> list<any>
range list<number>
table table

Examples

Return the first item of a list/table

> [123] |take1
╭───┬───╮
01
╰───┴───╯

Return the first 2 items of a list/table

> [123] |take2
╭───┬───╮
01
12
╰───┴───╯

Return the first two rows of a table

> [[editions]; [2015] [2018] [2021]] |take2
╭───┬──────────╮
# │ editions │
├───┼──────────┤
02015
12018
╰───┴──────────╯

Return the first 2 bytes of a binary value

>0x[012345] |take2
Length:2 (0x2) bytes|printablewhitespaceascii_othernon_ascii
00000000:0123#

Return the first 3 elements of a range

>1..10|take3
╭───┬───╮
01
12
23
╰───┴───╯

Subcommands:

name type usage
take until Builtin Take elements of the input until a predicate is true.
take while Builtin Take elements of the input while a predicate is true.

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