How to Remove Empty Lines From a Document or List
Learn how to remove blank lines from text safely — delete every empty line or collapse runs to one, without losing paragraph breaks or spacing that matters.
Paste a list from a PDF, a spreadsheet, or an email thread into a document and you often get a mess: every second or third line is empty and the list is twice as long as it should be. The fix is simple — remove the blank lines — but the details matter. A line that looks empty may hold a space or a tab, and a run of empty lines may be the only thing separating two paragraphs. This guide shows you how to remove blank lines from text: what counts as a blank line, how to delete them all or collapse them to one, and how to keep the spacing that actually means something.
Blank lines vs line breaks
A document is a sequence of lines, and every line ends with a line break — an invisible character that tells the editor to start a new line. A blank line is a line that contains nothing between two line breaks: no letters, no numbers, no punctuation.
The tricky case is the whitespace-only line. It looks empty on screen, but it contains one or more spaces or a tab — usually left behind when text is copied from a web page or a PDF. A cleanup that only checks for truly empty lines will leave these behind. Any reliable method therefore treats a line as blank when trimming it leaves nothing, whether it held zero characters or only spaces and tabs.
There is also a difference between a blank line and a line break. Removing a line break joins two lines into one; removing a blank line deletes an empty row and leaves the lines around it exactly where they were. Line endings add one more wrinkle: Windows text usually ends each line with a carriage return plus a line feed (CRLF), while macOS and Linux use a line feed alone (LF). A tool that only understands one style can leave stray carriage returns behind, which some editors show as extra blank lines. Good tools normalize line endings first, then remove the blank lines. Finally, remember that blank lines are not always noise: in prose, a single blank line is the separator between one paragraph and the next. That is why the best tools offer two modes — remove every blank line, or collapse each run of blank lines down to one.
The demo: a 10-line list, cleaned two ways
Here is the exact sample used for this guide — a ten-line task list copied from a spreadsheet export. Four lines hold real content; six hold nothing at all.
Data import task
Validate user input
Process results
Export to CSV
Run through a cleaner with the "remove all blank lines" mode, and the result is a tight four-line list. Nothing else changes: the wording, the order, and the capitalization are all exactly as they were.
Data import task
Validate user input
Process results
Export to CSV
That is the right result for a list. But watch what happens with a short piece of prose that uses blank lines as paragraph breaks:
Quarterly review notes
The import job ran cleanly and all four
source files were accepted.
Two warnings appeared in the log, both
related to date formats in the export.
Remove every blank line here and the three paragraphs collapse into one continuous block. The words are all still there, but the reader can no longer see where one thought ends and the next begins. The better choice for prose is "collapse to one": each run of blank lines becomes a single blank line, so the paragraph breaks survive while the excess gaps disappear.
Clean empty rows with the Whitespace Cleaner
The fastest reliable way to remove blank lines is a browser tool that does the work locally. FBSubNet's Whitespace Cleaner standardizes line endings, indentation, and blank lines in pasted text, and it runs entirely in your browser, so nothing you paste is uploaded anywhere. Here is the whole process:
- Paste your text into the tool's input box — a list, a block of prose, or a data export.
- Pick only the cleanup operations you need. For blank lines, use the option that reduces three or more consecutive newlines to two (the collapse behavior) or, if you are cleaning a list, remove the blank lines entirely. Leave the other options off unless you also need them.
- Run the tool and read the output. Check the beginning and the end of the text as well as the middle — that is where stray blank lines like to hide.
- Compare before and after. Count the lines before and after. In the demo above, the list went from ten lines to four; if your numbers do not match what you expected, you may have whitespace-only lines that need the trim option as well.
- Copy the cleaned result back into your document, spreadsheet, or email. Keep the original somewhere until you have checked the result in its final home.
Before pasting the result into its final home, check it in a plain-text editor with line numbers on. Problems that are invisible in a word processor — a line holding a single space, a double blank line between sections — are obvious when every line is numbered. If the text is sensitive, such as a client list or an internal export, prefer a tool that runs in the browser like this one: a server-side cleaner sends your data to someone else's computer, while a client-side tool keeps it on your device.
Other ways to remove blank lines
In Microsoft Word or Google Docs
Use Find and Replace. In Word, turn on "Use wildcards" and replace the pattern that matches two paragraph marks in a row with a single paragraph mark, repeating until no more replacements are made. In Google Docs, use Find and Replace with regular expressions turned on and replace the pattern that matches a blank line with nothing. Work on a copy, and replace in stages so you can stop at the level that looks right.
In a code editor with regular expressions
In VS Code, Sublime Text, or any editor with regex find-and-replace, the pattern ^\s*$\n matches a blank line: start of line, any whitespace, end of line, and the line break itself. Replacing matches with nothing removes every blank line, including whitespace-only ones. To collapse runs instead, replace \n{3,} with \n\n. One caution: in code files, blank lines often separate functions and blocks on purpose. Do not run a blanket removal over source code; use the collapse pattern there, or clean only the pasted data section.
In a spreadsheet, or from the command line
A column of values with empty rows between them is a common version of this problem. In Excel or Google Sheets, select the column, open the filter, and filter out blanks — or sort the column so the blanks collect at the bottom and delete those rows. The filter method is safer because it never moves your data. If the blank rows separate groups, do not delete them; filter temporarily to view only the filled rows. On macOS or Linux, grep -v '^$' input.txt > clean.txt drops every truly empty line, though it misses whitespace-only lines unless you trim first. Command-line methods are excellent for large files, but they rewrite the file, so work on a copy and check the line count before and after. For a list under twenty lines, manual deletion can be faster: turn on formatting marks so you can see the empty paragraphs, then delete them.
Avoid deleting meaningful spacing
The most common mistake in this whole job is treating every blank line as a defect. Blank lines carry meaning in more places than people expect, and a cleanup that ignores that will damage the text it was meant to fix.
In prose, a blank line is a paragraph break. Remove it and two ideas run together; in a long document the structure disappears entirely. In poetry and song lyrics, blank lines separate stanzas. In Markdown, a blank line is required between a paragraph and a list, a heading, or a blockquote — remove it and the formatting breaks. In data, a blank line can mark the boundary between records in a fixed-width export or a log file; delete it and two records merge into one. In code, blank lines separate logical blocks, and most style guides expect them there.
The rule that covers all of these cases is simple: clean a copy, and check the result before you replace the original. For a list, count the items before and after — the count should be identical. For prose, confirm the paragraph breaks are where you expect them. For data, confirm the record count is unchanged. And remember the two modes: "remove all" for lists and data exports, "collapse to one" for anything with paragraphs, stanzas, or sections. When you are unsure which kind of text you have, collapse — it never takes the last blank line away.
One more spacing decision is often confused with blank-line removal: trimming the spaces at the start and end of each line. That is a different cleanup, and a line with leading spaces may be indented on purpose — a nested list item, a quoted block, a line of code. If you are also cleaning extra spaces, do that as a separate pass. FBSubNet's guide to removing extra spaces from copied text covers that job, and pairing the two guides is the usual workflow for text pasted from a PDF: first fix the spaces inside lines, then fix the blank lines between them.
Troubleshooting: when blank lines refuse to disappear
Sometimes a cleanup seems to work and the gaps are still there. The "blank" line may hold a non-breaking space: text copied from a web page often uses non-breaking spaces for layout, and a normal space-trim will not remove them. Mixed line endings can also fool a cleaner: a document assembled from pieces copied on different systems can mix CRLF and LF endings, and some tools split lines on only one style. Normalizing line endings to one style before cleaning fixes this. The gaps may be paragraph spacing, not blank lines: in a word processor, a paragraph can have "space after" formatting that adds a visual gap without any empty line in the text — turn on formatting marks, and if there is no paragraph mark in the gap, adjust the paragraph spacing instead. Finally, the blank lines may come back after pasting, because some editors re-wrap pasted text. Pasting as plain text (usually Ctrl+Shift+V) avoids this.
Frequently asked questions
What is the difference between an empty line and a blank line?
An empty line holds zero characters between two line breaks. A blank line is the broader term: it includes empty lines and lines that hold only whitespace, such as spaces or tabs. In everyday use the two phrases mean the same thing.
Should I remove all blank lines or collapse them to one?
Remove all of them for lists, data exports, and anything where each line is an independent item. Collapse them to one for prose, notes, and anything where blank lines mark paragraph breaks. When in doubt, collapse — it is the safer default.
Do blank lines matter in code?
Usually they are cosmetic, but in whitespace-sensitive formats such as Python and YAML, indentation and blank lines can carry meaning. Never run a blanket blank-line removal over source code; collapse runs instead.
Blank lines are a small problem with an outsized annoyance factor: they double the length of a list, break the flow of a document, and make a clean export look careless. The fix takes seconds once you know which mode to use — remove them all for lists and data, collapse them to one for prose — and a quick before-and-after check keeps the spacing that matters. Paste the text into the Whitespace Cleaner, and the gaps are gone without touching a single word of your content.