Acquire / file · All operations

Read a text file line by line

A variant of Read another file format

Read a text file into a single string column with one row per line.

Status

In arcform

Runs as a SQL step

arcform carries it as a sql: step today.

The DuckDB step

Read a text file into one string column with a row per line

SQL
-- lines with commas, quotes, a tab, a blank line and non-ASCII text, and a final line with no newline
COPY (SELECT encode('id,name' || chr(10) || '1,"Alice, Ng"' || chr(10) || chr(10) || 'tab' || chr(9) || 'here' || chr(10) || 'Díaz;"x' || chr(10) || 'last'))
  TO '<your_scratch_dir>/text_lines.txt' (FORMAT blob);
CREATE TEMP TABLE result AS
SELECT unnest(arr) AS line, generate_subscripts(arr, 1) AS line_no
FROM (SELECT string_split_regex(regexp_replace(content, '\r?\n$', ''), '\r?\n') AS arr FROM read_text('<your_scratch_dir>/text_lines.txt') WHERE length(content) > 0);
SELECT * FROM result ORDER BY line_no;
SELECT CASE WHEN ((SELECT list(column_name) FROM (DESCRIBE result)) = ['line', 'line_no'] AND (SELECT list(line ORDER BY line_no) FROM result) = ['id,name', '1,"Alice, Ng"', '', 'tab' || chr(9) || 'here', 'Díaz;"x', 'last']) THEN 'as expected' ELSE error('the file did not read as six lines kept as written, including the blank one') 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 text_lines.txt itself, in <your_scratch_dir>.
  • It needs nothing installed beyond DuckDB itself.
  • The statement checks its own result and raises an error when it is wrong: “the file did not read as six lines kept as written, including the blank one”.
  • It passed on DuckDB v2.0.0 (Cyanoptera) d54cbbe3df.

What other tools call it

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

Apache NiFi (1)
  • TailFileread 2026-09-27

    Tail a text file, or a list of them, ingesting new lines as they are written

EasyMorph (1)
KNIME Analytics Platform (1)
  • Line Readerread 2026-09-27

    Read a file or URL line by line into a single string column

OpenRefine (1)
Polars (2)
  • read_linesread 2026-09-27

    Read the lines of a text file into one string column

  • scan_linesread 2026-09-27

    Lazily read the lines of a text file into one string column

VisiData (1)
  • txt (loader)read 2026-09-23

    Load plain text, one row per line

Background

In Polars, read_lines reads the lines of a file into a single string column, which is named line by default.[1] In KNIME, the Line Reader node reads a file or URL so that each line is a single string cell in a row of its own.[2]

When to use it

KNIME's Line Reader can replace empty lines with missing cells or with a custom text, or skip them so they are not added to the output.[2] Decide what a blank line means before reading: in a log it may be noise, while in an address block or a poem it is structure. (Meridian's view) KNIME's Line Reader decodes a file with the Java virtual machine's default encoding unless told otherwise, and that default may depend on the locale.[2] Name the encoding explicitly, so the same file reads the same way on every machine. (Meridian's view) Polars marks read_lines as unstable, so it may be changed at any point without that being considered a breaking change.[1]

The method

A newline is a control character, or a sequence of control characters, that signifies the end of a line of text and the start of a new one.[3] Microsoft Windows text files separate each line of text with a two-character combination, carriage return (CR) and line feed (LF).[4] In Windows text files it is common for the last line of text not to be terminated with a CR-LF marker.[4] On Unix-like operating systems, each line of a text file ends with a terminating newline character, normally LF.[4]

Newlines can be seen either as separators between lines or as terminators of lines, and a program that expects separators reads a final newline as starting a new, empty line.[3] Remove a single trailing line break before splitting a file into lines, or a file that ends in a newline gains an empty last row. (Meridian's view)

Sources

  1. [1]polars.read_lines — Polars documentationdocumentation
  2. [2]Line Readerdocumentation
  3. [3]Newline - Wikipediasecondary source
  4. [4]Text file - Wikipediasecondary source