Nodes/Comfy Text Stats/Text -> Remove Empty Lines
ComfyUI Node

Text -> Remove Empty Lines

The node that deletes blank lines so your text pipelines behave

By scofano·Created 11 months ago·Updated 3 months ago· 3
Text -> Remove Empty Lines
    • processed_text
    text

    Some nodes need a paragraph of explanation. This one needs a sentence: it takes multiline text and drops every line that's empty or whitespace-only. One input (text), one output (processed_text), no modes, no options. It's the smallest node in the Comfy Text Stats pack from scofano, and it's exactly as simple as it looks.

    Don't let the simplicity fool you - it earns its place. Copy-pasted captions, subtitle exports, and text wrangled out of chat apps are full of phantom blank lines that throw off line-based counts and make line-based chunking (like this pack's Line Batch Chunk) split in the wrong places. Run this first and everything downstream that cares about "line" semantics behaves.

    How it works

    It splits on newlines, keeps a line only if line.strip() is truthy, and rejoins with newlines. Lines of only spaces or tabs count as empty and go; real content keeps its original order. Note what it doesn't do: it's not a whitespace trimmer. A line like " hello " survives exactly as it was - this node removes empty lines, not leading or trailing whitespace within a line.

    Where it fits in a workflow

    It's usually first in a text-cleaning chain: paste → Remove Empty Lines → UTF-8 Cleaner (or Character Search Replace) → Text Stats to verify - then whatever consumes the result. Because it's a pure function with no state, it's safe to leave in a workflow and run on every execute.

    Installing it

    It's part of the Comfy Text Stats pack, so you get all eight nodes in one install. ComfyUI Manager route: Manager → Custom Nodes Manager → search "Comfy Text Stats" → Install, then restart ComfyUI. Or clone it manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/scofano/comfy-text-stats
    

    Restart after. No dependencies, no model downloads - the pack's requirements file is literally a comment saying there are none.

    Where people get burned

    There's one subtle gotcha, and it's a good argument for pairing this node with UTF-8 Cleaner. strip() only removes characters Python considers whitespace, and a zero-width space (U+200B) is not one of them. So a line that looks empty to your eye but contains an invisible zero-width character will survive this node. If blank lines seem to keep coming back, run UTF-8 Cleaner first to strip the invisible characters, then Remove Empty Lines - between the two of them your text is actually clean.

    CategoryText/Utils

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    processed_textSTRING