Home / Text tools / Remove empty lines

Remove Empty Lines

Delete blank lines from any text. Remove all of them, shrink long gaps to a single blank line, or clean up only the start and end.

Result

What the empty line remover does

Text copied from web pages, PDFs, emails and spreadsheets often arrives with blank lines between every line, or with long gaps in places. The tool cleans that up in one step and shows how many blank lines it found.

Three ways to remove blank lines

  • Remove all blank lines: every empty line goes, and the text becomes one block.
  • Collapse several blank lines into one: paragraphs stay separated, but a gap of five blank lines becomes one. This suits normal writing.
  • Remove blank lines at the start and end only: the middle of the text is left as it is.

Lines that look empty but are not

A line that contains only spaces or tabs looks empty, but a simple tool does not count it as empty. Keep Treat lines with only spaces as empty switched on, and those lines are removed too. Trim spaces at the start and end of each line also cleans the lines that stay.

Remove blank lines in other tools

  • Notepad++: Edit, Line Operations, Remove Empty Lines. The command Remove Empty Lines (Containing Blank Characters) also removes lines that hold only spaces.
  • VS Code: open Find and Replace, switch on regular expressions, search for ^\s*\n and replace with nothing.
  • Linux and macOS: grep -v '^[[:space:]]*$' file.txt or sed '/^[[:space:]]*$/d' file.txt.
  • PowerShell: Get-Content file.txt | Where-Object { $_.Trim() -ne '' }

Related tools

Delete repeated lines with remove duplicate lines, repeated words with remove duplicate words, and count what is left with the non-empty line counter. You can also sort lines or find and replace text. See the guide to removing duplicate lines for more ways to clean a list.

Frequently asked questions

How do I remove blank lines from text?

Paste the text and choose Remove all blank lines. Copy the result, or download it as a text file.

How do I keep paragraphs but remove extra blank lines?

Choose Collapse several blank lines into one. A single blank line stays between paragraphs.

Why are some blank lines not removed?

They probably contain spaces or tabs. Keep Treat lines with only spaces as empty switched on.

Does it change the text on the other lines?

No, unless you switch on Trim spaces. Otherwise the content of the lines is left exactly as it was.