Slice rows from any part of a CSV. When an index is present, this only has to parse the rows in the slice (instead of all rows leading up to the start of the slice).
Table of Contents | Source: src/cmd/slice.rs | 📇🏎️🗃️
Description | Examples | Usage | Slice Options | Common Options
Description ↩
Returns the rows in the range specified (starting at 0, half-open interval). The range does not include headers.
If the start of the range isn't specified, then the slice starts from the first record in the CSV data.
If the end of the range isn't specified, then the slice continues to the last record in the CSV data.
This operation can be made much faster by creating an index with 'qsv index' first. With an index, the command requires parsing just the rows that are sliced. Without an index, all rows up to the first row in the slice must be parsed.
Examples ↩
Slice from the 3rd record to the end
qsv slice --start 2 data.csvSlice the first three records
qsv slice --start 0 --end 2 data.csvSlice the first three records (using --len)
qsv slice --len 3 data.csvSlice the last record
qsv slice -s -1 data.csvSlice the last 10 records
qsv slice -s -10 data.csvGet everything except the last 10 records
qsv slice -s -10 --invert data.csvSlice the first three records of the last 10 records
qsv slice -s -10 -l 3 data.csvSlice the second record
qsv slice --index 1 data.csvSlice from the second record, two records
qsv slice -s 1 --len 2 data.csvSlice records 10 to 20 as JSON
qsv slice --start 9 --end 19 --json data.csvSlice records 1 to 9 and 21 to the end as JSON
qsv slice --start 9 --len 10 --invert --json data.csvFor more examples, see tests.
Usage ↩
qsv slice [options] [<input>]
qsv slice --helpSlice Options ↩
| Option | Type | Description | Default |
|---|---|---|---|
‑s,‑‑start |
string | The index of the record to slice from. If negative, starts from the last record. | |
‑e,‑‑end |
string | The index of the record to slice to. | |
‑l,‑‑len |
string | The length of the slice (can be used instead of --end). | |
‑i,‑‑index |
string | Slice a single record (shortcut for -s N -l 1). If negative, starts from the last record. | |
‑‑json |
flag | Output the result as JSON. Fields are written as key-value pairs. The key is the column name. The value is the field value. The output is a JSON array. If --no-headers is set, then the keys are the column indices (zero-based). | |
‑‑invert |
flag | slice all records EXCEPT those in the specified range. |
Common Options ↩
| Option | Type | Description | Default |
|---|---|---|---|
‑h,‑‑help |
flag | Display this message | |
‑o,‑‑output |
string | Write output to instead of stdout. | |
‑n,‑‑no‑headers |
flag | When set, the first row will not be interpreted as headers. Otherwise, the first row will always appear in the output as the header row. | |
‑d,‑‑delimiter |
string | The field delimiter for reading CSV data. Must be a single character. (default: ,) |
Source: src/cmd/slice.rs
| Table of Contents | README