W3cubDocs

/Nushell

where for filters

Filter values based on a row condition.

Signature

> where {flags} (row_condition)

Parameters

  • row_condition: Filter condition

Input/output types:

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

Examples

Filter rows of a table according to a condition

> [{a:1} {a:2}] |wherea>1
╭───┬───╮
# │ a │
├───┼───┤
02
╰───┴───╯

Filter items of a list according to a condition

> [12] |where {|x| $x>1}
╭───┬───╮
02
╰───┴───╯

List all files in the current directory with sizes greater than 2kb

>ls|wheresize>2kb

List only the files in the current directory

>ls|wheretype==file

List all files with names that contain "Car"

>ls|wherename=~"Car"

List all files that were modified in the last two weeks

>ls|wheremodified>= (date now) -2wk

Find files whose filenames don't begin with the correct sequential number

>ls|wheretype==file|sort-byname-n|enumerate|where {|e| $e.item.name!~$'^($e.index+1)' } |each {|| getitem }

Find case-insensitively files called "readme", without an explicit closure

>ls|where ($it.name|str downcase) =~readme

same as above but with regex only

>ls|wherename=~'(?i)readme'

Notes

This command works similar to 'filter' but allows extra shorthands for working with tables, known as "row conditions". On the other hand, reading the condition from a variable is not supported.

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