Remove Blank Lines

Remove blank or whitespace-only lines from any text. Content lines stay in their original order; only empty lines are dropped.

Example: first second thirdfirst 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.

When you reach for this

Cleaning text from PDFs

Copy-pasting from a PDF often inserts empty lines between paragraphs. Strip them in one pass before formatting.

Fixing double-spaced output

Some apps insert an empty line after every paragraph. Removing the blanks gives you tightly-packed prose.

Pre-processing for code

If you're feeding text to a parser line-by-line, removing blanks reduces edge cases.

Cleaning chat transcripts

Slack and Discord exports include empty lines between messages — strip them to get a compact transcript.

Tightening lists

Lists with empty separator lines look loose. Strip the blanks for tighter visual rhythm.

What gets processed (and how)

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.

How to use it

  1. Paste or type your text into the input area.
  2. Click the 'Remove Blank Lines' button.
  3. Verify the cleaned output appears in the result box.
  4. Copy the result or download it as a text file.

Behavior on tricky inputs

Trailing newlines
A single trailing newline is preserved as it follows the last non-blank line; multiple trailing newlines are treated as blank lines and removed.
CRLF vs LF line endings
The tool normalizes line endings to LF internally, so mixed line endings are handled consistently, and the output uses the original style.
Whitespace-only lines
Lines containing only spaces, tabs, or carriage returns are considered blank and removed, leaving visibly empty lines intact.

Workflow tips

  • Use after pasting text from a PDF to remove spurious line breaks while preserving paragraph structure.
  • Combine with a trim tool to remove leading/trailing whitespace from each line before blank-line removal.
  • Run on code to eliminate empty lines that break syntax highlighting or linting in some editors.
  • Process multiple files by concatenating them with a separator, removing blank lines, then splitting again.

vs other ways to do this

Compare with common alternative methods for removing blank lines.

This toolgrep -v '^$'Excel Filter
SpeedInstant for large files (client-side JavaScript)Fast for files up to millions of linesSlower for very large datasets due to row-based processing
Whitespace handlingRecognizes lines with any whitespace as blankOnly matches truly empty lines; requires pattern '^\s*$' to catch whitespace-onlyCan filter blank rows but not whitespace-only cells without a helper column
Ease of useOne-click web tool, no installationRequires command-line knowledgeRequires Excel and manual steps

Where this came from

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.

Common questions

Are whitespace-only lines treated as blank?

Yes — a line containing only spaces or tabs counts as blank and is removed.

Does it remove blank lines inside code blocks?

Yes — the tool doesn't know about syntax. If you need to preserve specific blank lines, manually paste them back after running the tool.

Will it collapse multiple blank lines into one?

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.

Does it change line endings?

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.

Embed our tools on your website

Free for any site. No signup. Iframe loads from our servers and stays up-to-date automatically.

📋 Embed the Word Counter

Copy this snippet:

Live preview:

📋 Embed this Remove Blank Lines

Copy this snippet:

Live preview:

Want more options? All embeddable tools →