How to Delete Blank Lines in Text, Word, Excel and Code Editors

Remove blank and whitespace-only lines from text, or collapse gaps to a single empty line, in a browser, Word, Excel, Notepad++, VS Code or the command line.

Updated September 29, 2026 5 min read

Use the free Remove Empty LinesDelete blank and whitespace-only lines or collapse them to one

Blank lines creep into text from everywhere. Copy a table from a PDF and every row is followed by an empty line. Export a list from an email and it arrives double-spaced. Paste log output, addresses or a column of product codes and you find gaps that break imports, sorting and counting. Sometimes you want every blank line gone; sometimes you want paragraphs kept but the three-line gaps squeezed down to one.

This guide explains why some "blank" lines are not really empty, shows how to clean them up in a browser in a few seconds, and covers the equivalent methods in Word, Excel, code editors and the command line.

Why blank lines are not always empty

A line that looks empty can contain several different things:

  • Nothing at all: two line breaks in a row. This is a truly empty line.
  • Whitespace: spaces, tabs or non-breaking spaces. It looks blank on screen, but a simple "is this line empty?" check says no.
  • Different line endings: Windows uses a carriage return plus line feed (CRLF), while macOS and Linux use a single line feed (LF). Text that mixes them can produce phantom blank lines in some programs.

Whitespace-only lines are the usual reason why a basic find-and-replace fails to remove every gap. A robust approach treats a line as blank if, after removing spaces and tabs, nothing is left.

Three ways to handle blank lines

Before you start, decide what result you want:

Goal Example use
Remove all blank lines A list of emails, SKUs or keywords that must be one item per line
Collapse runs of blank lines to one Prose or notes where paragraphs should stay separated, but gaps are uneven
Remove only leading and trailing blank lines A code snippet or template where the inner spacing is deliberate

Removing all blank lines from an essay would merge its paragraphs, so the middle option is usually right for anything written in paragraphs.

Remove empty lines in your browser

The Remove Empty Lines tool supports all three modes and tells you exactly how much it removed.

  1. Open Remove Empty Lines and paste your text into Text with blank lines. Click Sample to try a messy shopping list.
  2. Under What to remove, choose one of:
    • Remove all empty lines
    • Collapse runs to a single blank line
    • Only leading and trailing blank lines
  3. Keep Treat whitespace-only lines as empty switched on so that lines holding only spaces, tabs or no-break spaces are counted as blank.
  4. Optionally switch on Trim trailing spaces to remove invisible spaces at the end of the lines you keep.
  5. Read the summary under the output, for example "24 lines in, 15 lines out, 9 blank lines removed", then copy the Cleaned text or click Download.

Line endings are normalised automatically, so text copied from Windows and macOS programs behaves the same.

Other ways to delete blank lines

Microsoft Word

Word's Find and Replace can target paragraph marks. Open Replace, and in Find what enter ^p^p; in Replace with enter ^p. Click Replace All repeatedly until no replacements are made. This collapses double paragraph breaks, but lines that contain a space between the marks are not caught, and manual line breaks (Shift+Enter, shown as ^l) need a separate pass.

Excel and Google Sheets

If each line is in its own row, select the column, use Go To Special → Blanks in Excel to select all empty cells, then delete the rows. In Google Sheets, a filter that hides empty values, or a formula such as =FILTER(A:A, LEN(TRIM(A:A))>0), produces a list without the gaps. Cells that contain a single space will not count as blank unless you trim them first.

Notepad++ and VS Code

Both support regular-expression replace. To remove blank and whitespace-only lines, search for:

^\s*$\n

and replace it with nothing, with regular expressions enabled. Notepad++ also has a menu command under Edit → Line Operations to remove empty lines, with and without whitespace. Regular expressions are powerful, but a small mistake in the pattern can delete more than you expected, so keep an undo handy.

Command line

On macOS and Linux, grep or sed do the job for files:

grep -v '^[[:space:]]*$' input.txt > output.txt
sed '/^[[:space:]]*$/d' input.txt > output.txt

For collapsing multiple blank lines into one, cat -s squeezes repeated empty lines (truly empty ones). These commands are the best choice for large files or automated scripts, while a browser tool is quicker for text that is already on your clipboard.

Tips and troubleshooting

Some blank lines survive

They almost certainly contain invisible characters that are not spaces, such as zero-width spaces or control characters. Clean the text with the Text Cleaner first, then remove empty lines again.

Paragraphs merged together

You used "remove all" on text that relied on blank lines to separate paragraphs. Undo and use Collapse runs to a single blank line instead.

Every line ended up joined into one

That is a different operation. Removing empty lines deletes blank lines but keeps the line breaks between lines of text. If you do want to join lines into a paragraph, use Remove Line Breaks.

Cleaning a list before importing it

A typical sequence for a list of names, codes or addresses is:

  1. Remove empty lines.
  2. Trim extra spaces with Remove Extra Spaces.
  3. Remove duplicates with Remove Duplicate Lines.
  4. Sort the result with Sort Lines if the order does not matter.

Doing the steps in that order prevents blank lines from being treated as a duplicate "value" or sorting to the top of your list.

Frequently asked questions

What is a whitespace-only line?

It is a line that contains spaces, tabs or non-breaking spaces but no visible characters. It looks empty but is not technically empty, so simple methods often miss it.

How do I keep one blank line between paragraphs?

Choose Collapse runs to a single blank line. Any group of two or more blank lines becomes exactly one, and blank lines at the very start and end are removed.

Will removing empty lines change my text in other ways?

No. Only blank lines are removed, plus trailing spaces if you switch that option on. The text on the remaining lines and their order are unchanged.

Why does Word's ^p^p trick not remove everything?

It only matches two paragraph marks directly next to each other. Lines with a space in between, or manual line breaks, need extra replacement passes.

Can I remove blank lines from a very large file?

The browser tool handles long texts comfortably, but for files of many megabytes a command-line tool such as sed or grep is faster and does not require copying and pasting.

Try it now: Remove Empty Lines

Loading tool…