Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

record where for filters

Keep the fields of a record for which a row condition or closure is true.

Command Type

built-in

Signature

> record where {flags} (condition)

Flags

  • --keys, -k: Pass only the key, as $it in a row condition, as a closure's argument, and as $in.
  • --values, -v: Pass only the value, as $it in a row condition, as a closure's argument, and as $in.

Parameters

  • condition: The row condition or closure that decides whether to keep each field.

Input/output types:

inputoutput
recordrecord
tabletable
list<any>list<any>

Examples

Keep the fields whose value is greater than one.

> {a: 1, b: 2, c: 3} | record where value > 1
╭───┬───╮
│ b │ 2 │
│ c │ 3 │
╰───┴───╯

Keep the fields whose key starts with NU_.

> {NU_LOG: debug, HOME: /home/me, NU_THEME: dark} | record where key starts-with NU_
╭──────────┬───────╮
│ NU_LOG   │ debug │
│ NU_THEME │ dark  │
╰──────────┴───────╯

Keep the fields whose value is greater than one, with a closure.

> {a: 1, b: 2, c: 3} | record where {|key, value| $value > 1}
╭───┬───╮
│ b │ 2 │
│ c │ 3 │
╰───┴───╯

Drop the fields with empty values.

> {name: app, desc: '', tags: []} | record where --values { is-not-empty }
╭──────┬─────╮
│ name │ app │
╰──────┴─────╯

Drop the empty fields of every row of a table.

> [{a: 1, b: ''} {a: '', b: 2}] | record where --values { is-not-empty }
╭───┬────┬────╮
│ # │ a  │ b  │
├───┼────┼────┤
│ 0 │  1 │ ❎ │
│ 1 │ ❎ │  2 │
╰───┴────┴────╯

Notes

A row condition sees each field as a {key, value} record, the rows where would see after transpose key value. So record where value > 1 filters on the value and record where key starts-with NU_ on the key. A closure instead receives each field's key and value as two arguments, like items, and $in is empty. With --keys or --values, the condition receives only the key or only the value. A row condition gets it as $it, a closure as its argument, and both as $in, so a closure needs no parameters. Put --keys and --values before the condition, because a row condition takes everything after it. record where keeps the matching fields in their original order. Given a list of records, each record is filtered on its own and the results are streamed.