first
Synopsis
any |> first <count>
Description
first passes on the first count input records and drops the rest. The
stage reads no more than count records from its input, so the source stops
once they are read; first 0 reads nothing. The planner passes the count to
the sources of the pipeline, which may stop early.
The order, the header and the presentation hint of the stream are kept. An
input with fewer records than count passes on whole.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
count |
int |
required | Number of records to keep. |
Input and output
| Form | Input | Output |
|---|---|---|
| default | any |
same |
Effect
| Property | Value |
|---|---|
| Category | transform |
| Effect | read |
| Reversibility | read |
| Implementation | builtin |
Examples
Keep the first two files:
find "/home/user/project" |> first 2
Keep the largest file:
find "/home/user/project" |> sort size order: desc |> first 1
Show the first two lines of a log:
lines "/home/user/app.log" |> first 2
Errors
| Code | Meaning | Typical fix |
|---|---|---|
E_MISSING_PARAM |
count is missing |
write a number after first |
E_INVALID_VALUE |
count is negative |
use 0 or a larger number |
E_TYPE |
count is not an integer |
write an integer, for example first 20 |
Related
last, skip, sort.