Row Head/Tail Slice N
Take the first or last N CSV data records in their original order, retaining an explicitly declared header and treating quoted multiline cells as one record.
Description
A CSV record can span several physical lines.
A CSV record can span several physical lines. Head/tail sampling should operate on logical records and preserve a deliberate header policy.1
Take the first or last N CSV data records in their original order, retaining an explicitly declared header and treating quoted multiline cells as one record.
When to use Row Head/Tail Slice N
Use this for the following task: Take the first or last N CSV data records in their original order, retaining an explicitly declared header and treating quoted multiline cells as one record.
Prepare the CSV text, decoded cells or byte values requested below. Choose delimiter and header flags explicitly when those fields are present.
How to use Row Head/Tail Slice N and understand its results
- Prepare the CSV text, decoded cells or byte values requested below. Choose delimiter and header flags explicitly when those fields are present.
- Enter csv, delimiter, hasHeader, side, count using the field table, then run the tool.
- Read csv. Interpret flags, units, ordering and placeholder values using the rules below.
- Review any reported issue or failed check, correct the supplied values when appropriate, and verify the result in its intended context.
| Input field | Meaning | Value type and bounds | Requirement |
|---|---|---|---|
| csv | CSV text | string; maximum text length 100000 | Required |
| delimiter | Delimiter | string; choose ",", ";", "\t" | Required |
| hasHeader | Has header | boolean | Required |
| side | Side | string; choose "head", "tail" | Required |
| count | Count | integer; minimum 0 | Required |
Parse records, separate an optional header and choose head or tail with a nonnegative count. Count zero selects no data; a count above available data selects all.2
Parse delimiters only outside quoted fields and decode doubled quotes. A quoted line break stays inside its cell; malformed quoting is returned as an input error.
The shared writer doubles interior quotes and quotes cells when needed for delimiters or line breaks, including a single empty-field record. It normally emits LF record endings without a terminal newline; any tool-specific quote-all behavior is stated above.
selected = first N or last N data records, in their original order This summarizes the declared operation. Units, indexing, inclusivity and exceptional cases are explained in the surrounding text.
| Output field | Meaning | Value type |
|---|---|---|
| csv | CSV text | string |
{
"input": {
"csv": "name\nAda\nGrace\nKatherine",
"delimiter": ",",
"hasHeader": true,
"side": "tail",
"count": 2
},
"output": {
"csv": "name\nGrace\nKatherine"
}
} Limitations and assumptions
The writer normalizes quote spelling and uses LF without a terminal newline. Header presence is not guessed.
Where CSV is parsed, the shared parser accepts comma, semicolon or tab separators, doubled quotes and quoted line breaks, with CR/LF/CRLF record endings. Blank records remain records. CSV inputs are bounded to 100000 UTF-16 units and 10000 fields. Malformed requests produce input errors. A successfully evaluated request can still contain false flags, empty result lists or a result outside the supplied threshold; those outcomes have the meanings stated above.
Alternative or Complementary methods
Choose CSV Row Counter for this operation: Count CSV records including blank records and quoted multiline fields, with an explicit header flag; physical lines are not records. For a complementary task, use First-N Distinct Values Per Column for this operation: Sample the first N distinct decoded data values per column in encounter order, counting empty strings as values and reporting the full distinct count.
Further background: Format and language reference: Row Head/Tail Slice N.
References
-
Format and language reference: Row Head/Tail Slice N — RFC Editor
-
Row Head/Tail Slice N — tool.io
Similar or alternative tools
- CSV Row Counter
Count CSV records including blank records and quoted multiline fields, with an explicit header flag; physical lines are not records.
- First-N Distinct Values Per Column
Sample the first N distinct decoded data values per column in encounter order, counting empty strings as values and reporting the full distinct count.