Remove Blank Lines Tool

Paste your text to remove every blank line.

How it is calculated

The text is split at every line break (Windows \r\n, old Mac \r or Unix \n). A line is dropped when it has nothing left after ordinary spaces, tabs and line-break characters are trimmed away; every other line is kept exactly as typed and the survivors are joined with plain \n line breaks. Because only the test uses trimming, indentation and trailing spaces on kept lines stay untouched. The counts are removed = total lines − kept lines. A newline at the very end of the input creates one more empty line, so it is counted as a removed line. Input that is empty or only whitespace gives no result. Lines are never merged, reordered or de-duplicated.

Worked example

The input has six lines: apple, an empty line, a line holding only three spaces, banana, another empty line, and cherry. The empty line and the spaces-only line are both blank after trimming, and so is the second empty line, so three lines are dropped. The result is apple, banana, cherry on consecutive lines, and the tool reports 3 lines removed and 3 lines kept.

Try this example →

Common mistakes

  • Expecting this to collapse several blank lines into one; every blank line is removed, so paragraphs lose their separating gap.
  • Thinking that a line with only a space or tab survives because it looks empty; whitespace-only lines are removed too.
  • Being surprised that the removed count is one higher than the visible blank lines, when the pasted text ends with a line break.
  • Expecting leading or trailing spaces on the remaining lines to be trimmed; only the blank-line test trims, the lines themselves are copied unchanged.
  • Expecting lines that hold only a non-breaking space or a zero-width space to disappear; they look empty but are kept, because only ordinary spaces, tabs and line-break characters count as blank.

About this calculator

This tool strips every empty line and every line containing only whitespace (spaces, tabs) from a block of text, splitting the input on line breaks, filtering out lines that are empty after trimming, and rejoining what remains.

Blank lines accumulate for mundane reasons — pasted content, exported CSV or log files, code that mixes tabs and spaces, or text copied from a PDF or word processor — and they clutter output that needs to be compact, such as configuration files, mailing lists, or data prepared for import into another tool.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    The lines-kept count doubles as a quick way to count the real entries in a pasted list, such as addresses, SKUs or log lines, without the gaps skewing the number. Keep in mind the surviving lines are copied untouched, so a stray trailing space can make two identical-looking entries differ later when you de-duplicate or import them. What are you cleaning up, a log, a spreadsheet column, or text from a PDF? Tell us where the stray blanks come from.

Popular calculators

All Calculators