group

Synopsis

any |> group <by> [name: value]...

Description

group computes by for each record and gives one group record per distinct value, with the fields key (the value) and count (the number of records). With keep_items: true the field items holds the records of the group in input order. Values compare by the total order of values.

Groups are ordered by their key, so the output does not depend on the order of the input; the output declares this order. group reads the whole input; the number of groups, and with keep_items the number of held records, is bounded by the record limit of the request. An empty input gives no groups.

Parameters

Parameter Type Default Description
by field | expression required Field or expression whose value forms the groups.
keep_items bool false Include the records of each group.

Input and output

Form Input Output
default any group

Effect

Property Value
Category transform
Effect read
Reversibility read
Implementation builtin

Examples

Count the files of each extension:

find "/home/user/project" |> group extension

Group the files by extension and keep them in each group:

find "/home/user/project" |> group extension keep_items: true

Split files into small and large ones:

find "/home/user/project" |> group size > 2kb

Errors

Code Meaning Typical fix
E_MISSING_PARAM by is missing name a field or write an expression
E_UNKNOWN_FIELD by names a field the records do not have; expected lists their fields use one of the listed fields
E_LIMIT more groups or records than the limit narrow the input or omit keep_items

summarize, distinct, sort, count.

Source file on GitHub: docs/commands/group.md