Remove Blank Lines
Remove blank or whitespace-only lines from any text. Content lines stay in their original order; only empty lines are dropped.
first
second
third → first
second
third
Remove blank or whitespace-only lines from any text. Content lines stay in their original order; only empty lines are dropped.
first
second
third → first
second
third
Removes blank lines from a block of text. A line is treated as blank if it contains nothing or only whitespace (spaces, tabs). All non-empty lines stay in their original order.
Useful for cleaning up text pasted from PDFs, fixing double-spaced paragraphs, or normalising multi-line output before further processing.
Copy-pasting from a PDF often inserts empty lines between paragraphs. Strip them in one pass before formatting.
Some apps insert an empty line after every paragraph. Removing the blanks gives you tightly-packed prose.
If you're feeding text to a parser line-by-line, removing blanks reduces edge cases.
Slack and Discord exports include empty lines between messages — strip them to get a compact transcript.
Lists with empty separator lines look loose. Strip the blanks for tighter visual rhythm.
The tool reads the input text and splits it into an array of lines using the newline character (\n) as delimiter. For each line, it tests whether the trimmed string matches the regular expression /^\s*$/ — a line that contains zero or more whitespace characters (spaces, tabs, carriage returns) is considered blank. Lines that do not match are collected into a new array preserving their original order. The tool handles both Unix (LF) and Windows (CRLF) line endings by normalizing line breaks before processing. After filtering, the non-blank lines are joined back with the original line-ending style (LF or CRLF) to maintain consistency with the input. The algorithm runs in O(n) time relative to the number of lines, making it efficient even for large texts.
Compare with common alternative methods for removing blank lines.
| This tool | grep -v '^$' | Excel Filter | |
|---|---|---|---|
| Speed | Instant for large files (client-side JavaScript) | Fast for files up to millions of lines | Slower for very large datasets due to row-based processing |
| Whitespace handling | Recognizes lines with any whitespace as blank | Only matches truly empty lines; requires pattern '^\s*$' to catch whitespace-only | Can filter blank rows but not whitespace-only cells without a helper column |
| Ease of use | One-click web tool, no installation | Requires command-line knowledge | Requires Excel and manual steps |
The practice of removing blank lines originates from early Unix text processing utilities. The grep command, introduced in 1974 by Ken Thompson, could filter lines matching a pattern; grep -v '^$' became a standard idiom to delete empty lines. Later, sed offered in-place editing with sed '/^$/d'. These tools, designed for stream editing and pipeline use, established the paradigm of efficient, pattern-based line removal that modern web tools like this one emulate.
Yes — a line containing only spaces or tabs counts as blank and is removed.
Yes — the tool doesn't know about syntax. If you need to preserve specific blank lines, manually paste them back after running the tool.
It removes them entirely. If you want "at most one blank line between paragraphs", run the tool then re-add a single blank line where you need it.
It normalises Windows-style \r\n into Unix-style \n in the output. Most apps render both identically; if you need Windows endings specifically, convert after.