# Count the rows in files

Acquire / filesystem

A variant of [List files and folders](https://meridian.online/operations/list-files-and-folders).

Return the number of rows in one or more text files without loading them as a table.

Page: <https://meridian.online/operations/list-files-and-folders/count-the-rows-in-files>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

count the rows of text files without loading them as a table

```sql
COPY (SELECT ('a' || chr(10) || 'b' || chr(10) || chr(10) || 'd' || chr(10))::BLOB) TO '<your_scratch_dir>/rows_a.txt' (FORMAT blob);
COPY (SELECT ('x' || chr(10) || 'y')::BLOB) TO '<your_scratch_dir>/rows_b.txt' (FORMAT blob);
COPY (SELECT ''::BLOB) TO '<your_scratch_dir>/rows_c.txt' (FORMAT blob);
-- a line is a newline, plus one for a last line that has none
CREATE TEMP TABLE result AS
SELECT replace(filename, '<your_scratch_dir>/', '') AS file,
       length(content) - length(replace(content, chr(10), '')) + CASE WHEN length(content) > 0 AND NOT content LIKE '%' || chr(10) THEN 1 ELSE 0 END AS line_count
FROM read_text('<your_scratch_dir>/rows_*.txt');
SELECT * FROM result ORDER BY file;
SELECT CASE WHEN ((SELECT list(line_count ORDER BY file) FROM result) = [4, 2, 0] AND (SELECT sum(line_count) FROM result) = 6) THEN 'as expected' ELSE error('the three files did not count as 4, 2 and 0 lines, 6 in all') END AS verdict;
```

Replace `<your_scratch_dir>` with a directory of your own that you can write to before running the statement.

The statement writes `rows_a.txt`, `rows_b.txt` and `rows_c.txt` itself, in `<your_scratch_dir>`.

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Apache Hop: [`Get files rowcount`](https://hop.apache.org/manual/latest/pipeline/transforms/getfilesrowcount.html) (read 2026-09-27)
- Pentaho Data Integration: [`Get Files Rows Count`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Talend: [`tFileRowCount`](https://help.qlik.com/talend/en-US/components/8.0/tfilerowcount/tfilerowcount-component) (read 2026-09-27)
