head
Operator
head — copy leading values of input sequence
Synopsis
head [ <const-expr> ]
Description
The head
operator copies the first N values from its input to its output and ends
the sequence thereafter. N is given by <const-expr>
, a compile-time
constant expression that evaluates to a positive integer. If <const-expr>
is not provided, the value of N defaults to 1
.
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"}