Skip to main content
Version: v1.14.0

head

Operator

head copy leading values of input sequence

Synopsis

head [ <expr> ]

Description

The head operator copies the first n values, evaluated from <expr>, from its input to its output and ends the sequence thereafter. <expr> must evaluate to a positive integer at compile time.

Examples

Grab first two values of arbitrary sequence

echo '1 "foo" [1,2,3]' | zq -z 'head 2' -

=>

1
"foo"

Grab first two values of arbitrary sequence, using a different representation of two

echo '1 "foo" [1,2,3]' | zq -z 'head 1+1' -

=>

1
"foo"

Grab the first record of a record sequence

echo '{a:"hello"}{b:"world"}' | zq -z head -

=>

{a:"hello"}