Text File Line Reader ⏲️
Pull one specific line out of a text file
- line_text
If Text File Line Counter answers "how many lines does this file have," this one answers the natural follow-up: "give me line number N." Point it at a text file, and it hands you back the text of one specific line as a string - the obvious use being a prompt list, a wildcard file, or a captions file where each line is a separate thing you want to feed into a workflow one at a time.
It's the companion piece to the rest of this pack rather than something you'd reach for alone. The clean combo is: Text File Line Counter tells you how many lines a file has, Simple Number Counter walks a value up to that total one run at a time, and Text File Line Reader (in index mode) pulls whichever line that counter currently points at - straight into a CLIP Text Encode or wherever the text needs to land. Three tiny nodes standing in for what would otherwise be a short Python script.
How it works
mode picks between two ways of choosing the line. index mode is the direct route - you set the index field yourself and the node reads that exact line. automatic mode, going by its name, is built to advance through the file rather than you setting a number each time, the same "hold state across runs" trick the rest of this pack's counter node uses - useful if you just want each successive queue run to grab the next line without you touching anything. There's no reset control on this node itself, so if you're using automatic mode and need to jump back to the top of the file, restarting ComfyUI is the reliable way to do it.
The inputs and outputs that matter
file_path(STRING) - the text file to read from.mode-automaticorindex. Pickindexwhen you want explicit control (usually paired with a counter node feeding the index in);automaticwhen you just want it to step forward on its own.index(INT, default 0) - which line to grab whenmodeisindex. It's zero-based - line 1 in your text editor is index0here, a classic off-by-one to watch for.
One output: line_text (STRING) - the text of that line, ready to wire into a prompt input, a Show Text node, or anything else expecting a string.
Installing it
ComfyUI Manager: search ComfyUI-Line-counter, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ChrisColeTech/ComfyUI-Line-counter.git
Restart ComfyUI. No dependencies, no downloads - plain file I/O.
Common issues and troubleshooting
The most common one is the off-by-one: forgetting index starts at 0, wiring in a total line count that's meant for "how many lines exist" straight into index, and getting an out-of-range read one line past the end of the file. If you're driving index from Text File Line Counter's output, subtract one, or clamp your loop to count - 1.
Second: file_path needs to point at a real plain-text file on the machine actually running the workflow - same caveat as the rest of this pack, no browse dialog, no autocomplete, just a string you have to get right. And it's a text-line reader, not a JSON or CSV parser - if a "line" in your file is really a serialized row with its own structure, you're getting that whole line back as one raw string, unparsed. Anything past that is your job downstream.
If automatic mode isn't advancing the way you expect - same line coming back run after run, or picking up mid-file when you wanted the start - treat it the same way you'd treat Simple Number Counter behaving unexpectedly: it's holding state in memory, and there's no reset input here to snap it back, so a ComfyUI restart is the blunt-but-reliable fix.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | STRING | — | |
| mode | COMBO | automatic | 2 options: automatic, index |
| index | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| line_text | STRING | — |