BLOG / GUIDE · 2026-05-09 · 7 min

How to remove blank lines from text

Five practical ways to delete blank or whitespace-only lines — Excel filter, Notepad++ regex, the awk one-liner, or an instant browser tool. With the empty-vs-blank-line trap most regex misses.

The short answer. Paste your text into the line break remover with Drop blanks turned on — one click, done. In Excel, sort the column and the blank rows fall to the bottom; or filter for non-blanks. In Notepad++ with regex on, search ^\s*\r?\n and replace with nothing. On the command line, awk 'NF' file.txt in eight characters does the whole job. The trick is knowing whether a "blank" line is empty (just a newline) or whitespace-only (newline plus invisible spaces/tabs) — most naive deletions miss one or the other. The decision table at the bottom maps your situation to the right method.

Empty lines vs blank lines: not the same thing

Two definitions get confused, and the difference is the reason "remove blank lines" sometimes doesn't work the first time:

  • Empty line — literally just a line ending (\n or \r\n). Nothing between two consecutive newlines.
  • Whitespace-only / blank line — a line that contains spaces, tabs, or other invisible whitespace, but no visible characters.

Visually identical in the editor. Different to match. A regex that targets only ^$ ("start of line immediately followed by end of line") will catch empty lines and miss whitespace-only ones — the most common cause of "I removed the blank lines but some are still there". To catch both, the pattern is ^\s*$ ("start of line, any amount of whitespace, end of line").

Files exported from Excel are the worst offender: they often have rows that look blank but contain a single space, a non-breaking space, or a stray tab. A clean removal needs to target the whitespace-tolerant pattern.

How do you remove blank lines online, instantly?

Open the line break remover. Paste your text. Turn on Drop blanks. Copy the result.

  • Handles both kinds. The toggle uses the whitespace-tolerant rule — lines that look blank but contain stray spaces or tabs are dropped along with truly empty ones. We test it against Excel-export edge cases (stray non-breaking spaces, mixed indentation) before each release.
  • Keeps paragraph breaks when you want them. Combine with Keep paragraphs if you only want to drop runs of multiple consecutive blank lines while keeping single-blank-line paragraph breaks intact.
  • Order preserved. The output keeps your original line sequence, just with the blanks removed.
  • Nothing uploads. Open DevTools → Network and run the transformation; zero outbound requests carrying your text.

How do you remove blank lines in Notepad++ or VS Code?

The right regex pattern is the only thing to remember.

Notepad++

  1. Press Ctrl+H.
  2. Set Search Mode to Regular expression.
  3. In Find what: ^\s*\r?\n — matches empty lines and whitespace-only lines, on Windows or Unix line endings.
  4. Leave Replace with blank.
  5. Click Replace All.

For just empty lines without whitespace tolerance: ^\r?\n. For collapsing runs of multiple blank lines into a single blank line (keeping intentional paragraph spacing untouched): search (\r?\n){3,} and replace with \r\n\r\n (Windows files) or \n\n (Unix files) — this fires only when there are two or more blank lines, leaving single-blank paragraph separators alone.

VS Code

  1. Press Ctrl+H on Windows / Linux, Cmd+Opt+F on macOS.
  2. Click the .* icon to enable regex.
  3. Search for ^\s*\r?\n. The ? makes the carriage return optional, so the same pattern catches both Windows and Unix line endings.
  4. Replace with nothing.

How do you remove blank rows in Excel?

"Blank line" in Excel usually means "row with no content". Two clean paths:

Sort the column.

  1. Select the column.
  2. Data → Sort A to Z.
  3. Blank cells fall to the bottom; select and delete the whole rows.

This destroys the original ordering. If that matters, use a filter instead.

Filter, then copy out the non-blank rows.

  1. Select the column. Data → Filter.
  2. Click the column header dropdown; uncheck (Blanks). Now only non-blank rows are visible.
  3. Select the visible rows and copy them to a new sheet.

Filter, then delete the blank rows.

  1. Select the column. Data → Filter.
  2. Click the column header dropdown; uncheck everything except (Blanks). Now only blank rows are visible.
  3. Select the visible rows, right-click, Delete Row. Turn the filter off — only your non-blank rows remain.

For a formula-based extraction that preserves order:

=FILTER(A2:A100, A2:A100 <> "")

Modern Excel and Google Sheets share this syntax. Older versions of Excel need a helper column with =IF(ISBLANK(A2), "", ROW()) and an INDEX/SMALL combination to extract — ugly enough that switching to the filter UI is usually faster.

How do you remove blank lines on the command line?

Three short recipes, increasingly tolerant of what counts as "blank".

grep — for empty lines only:

grep -v '^$' file.txt

Prints every line that doesn't match "start immediately followed by end" — effectively, every non-empty line. Doesn't catch whitespace-only lines.

sed — for whitespace-tolerant removal:

sed '/^[[:space:]]*$/d' file.txt

The POSIX character class [[:space:]] is more portable than \s — works on both GNU sed (Linux) and BSD sed (macOS) without flags. The /d deletes lines that match.

awk 'NF' — the cleanest one:

awk 'NF' file.txt

NF is "number of fields"; with the default field separator (whitespace runs), a line with only ordinary spaces or tabs has zero fields, so the implicit "print if true" condition skips it. Eight characters, no regex. The Unix one-liner that wins on aesthetics.

On Windows in PowerShell:

Get-Content file.txt | Where-Object { $_.Trim() -ne "" } | Set-Content out.txt

Which method should you use?

Where the text isFastest method
Pasted from anywhere, one-offBrowser tool with Drop blanks on
An Excel columnSort A→Z, blanks fall to the bottom; or =FILTER(...)
A Google Sheet=FILTER(A2:A100, A2:A100 <> "")
Open in Notepad++ or VS CodeRegex ^\s*\r?\n
A file on disk, scriptedawk 'NF' file.txt
Need to collapse runs of blanks into oneBrowser tool's Keep paragraphs, or regex (\r?\n){3,}
Sensitive dataBrowser tool or local command line — never an upload site

Frequently asked questions

Why does my regex remove some blank lines but not others?

Almost always because the regex targets ^$ (truly empty) but some lines contain whitespace (a space, tab, or non-breaking space). Switch to ^\s*$ for whitespace-tolerant matching. The browser tool's Drop blanks toggle is whitespace-tolerant by default, sidestepping the gotcha entirely.

How do I remove blank lines without changing the order of the remaining lines?

Every method on this page preserves order except Excel's "sort the column" approach, which by definition reorders. The cleanest order-preserving paths are the browser tool, awk 'NF', and the regex Find & Replace in any editor. In Excel, use the filter or =FILTER() formula instead of sort — both preserve the original row order.

How do I keep paragraph breaks but remove extra blank lines?

Treat "more than one consecutive blank" as the target, not "any blank". The browser tool's Keep paragraphs mode keeps single blank-line separators between paragraphs and collapses runs of two or more. In regex, search (\r?\n){3,} and replace with \r\n\r\n (Windows) or \n\n (Unix) — this matches runs of three or more consecutive newlines (two or more blank lines) and collapses them to one blank line. Single blank lines stay untouched.

What if the "blank" line contains a non-breaking space?

Non-breaking space (U+00A0) is the most common silent trap. Tools disagree on whether \s matches it. POSIX regex usually does not. GNU tools depend on the locale — UTF-8 catches NBSP, C locale does not. JavaScript's \s matches it. The honest answer: do not rely on \s alone when NBSP is suspected. The browser tool handles NBSP because JavaScript's String.prototype.trim() covers U+00A0 by spec. On the command line, the safe explicit pattern uses the UTF-8 byte sequence directly — for example perl -ne 'print unless /^[\s\x{00a0}]*$/', or grep -vP '^[\s\x{00a0}]*$' with PCRE. Plain awk 'NF' is not NBSP-safe by default: NBSP is treated as part of a field, so a line of only NBSP would be kept, not skipped. We test against U+00A0 specifically because Excel exports surface it constantly.

How do I find which lines were removed, not just remove them?

Inverse the filter. grep -nE '^[[:space:]]*$' file.txt on the command line prints every blank line with its line number — POSIX character class for cross-platform reliability (BSD grep on macOS doesn't recognise \s by default). In an editor, do the Find with regex on but don't replace — the Find dialog will tell you how many matches and where. Useful when you want to confirm the cleanup didn't drop anything you needed.

Is it safe to paste sensitive text into an online blank-line remover?

Only if the tool runs entirely in the browser. Open DevTools, switch to the Network tab, paste, run the transformation, watch for outbound requests. If any carry your data, the page sent it to a server. The joinlines tool makes zero requests after page load — verifiable in DevTools.

— the joinlines team, 2026-05-09

§ — PRIVACY Your text never leaves your browser. No upload, no account, no logs on what you paste.
PRIVACY PAGE ↗