What is Remove Empty Lines?
A Remove Empty Lines computes remove empty lines from the inputs you provide. It applies the standard formula to the values you enter and returns the result instantly, without sending any data to a server. Strip every blank or whitespace-only line from pasted text while keeping the rest of the line structure intact.
Remove Empty Lines
Strip every blank or whitespace-only line, keep the rest. Great for cleaning up logs and copy-pasted code.
TLDR
Splits the input on line breaks, drops any line whose trimmed content is empty, then joins the survivors back together.
How to use this tool
- Paste your text. Drop in the content - log, snippet, list, transcript.
- Press Remove blanks. Every blank line disappears, the rest stays in order.
- Copy the result. Drop the compacted version where you need it.
- Restore CRLF if your editor needs it. Output is LF-only; re-save with your editor's line-ending option if necessary.
Real-world scenarios where this tool helps
Log file cleanup
Many runtimes emit blank lines between entries. Strip them for compact review.
Email reply cleanup
Replies pile up with blank lines from quoting. Compress before forwarding.
Snippet posting
Stack Overflow and Reddit waste vertical space if your snippet has stray blank lines.
Spreadsheet imports
Excel and Google Sheets paste-as-rows; blank rows become empty cells that mess up sort.
Markdown lists
Some renderers break a list when a blank line appears mid-list. Strip before publishing.
What this tool does
- Splits the input on both LF and CRLF line breaks.
- Drops every line whose trimmed content is empty (zero chars or whitespace only).
- Joins the surviving lines back with a single LF separator.
- Preserves the order of surviving lines.
- Preserves indentation and trailing whitespace within each kept line.
What it does NOT do
- Does not merge consecutive non-blank lines.
- Does not de-duplicate lines - use the Remove Duplicate Lines tool for that.
- Does not strip trailing whitespace inside surviving lines.
- Does not convert CRLF to LF on input - it just doesn't preserve the CRLF (output uses LF).
- Does not save text to a server.
About blank-line removal
Blank lines are visual breathing room: a stack trace separates frames with one, an email reply quotes a sender's lines, an essay drafted in Word leaves a gap after every paragraph. When you paste that content into a chat, a status page, a code review comment, or a tightly formatted PDF, the gaps become wasted vertical space. This tool collapses every fully blank line in one pass while leaving the content of every kept line untouched.
The rule is strict: a line is "blank" only if it contains zero non-whitespace characters. A line with a single visible glyph survives. That keeps things predictable when the text being cleaned is technical (config files, code snippets, log output) and you cannot afford to lose a leading-space indent or a tab. If you want stronger cleanup, run the output through a trim or normalise-whitespace tool afterwards.
How the algorithm works
return input
.split(/\r?\n/) // split on LF or CRLF
.filter(l => l.trim()) // drop blanks
.join('\n'); // rejoin with LF
The split regex handles both Unix and Windows line endings. The filter calls String.prototype.trim() on each line; if the result is the empty string the line is dropped. The join uses LF, so the output is consistent regardless of input ending. Time complexity is O(n) in the input length.
Worked example
Input (9 lines, 4 blank):
2026-05-28 09:14 INFO server started (whitespace-only line) 2026-05-28 09:14 INFO listening on :8080 (empty line) 2026-05-28 09:15 ERROR db timeout 2026-05-28 09:15 INFO retrying
Lines 2, 3, 5, 6 and 8 are blank (zero or whitespace-only). They are dropped. Lines 1, 4, 7 and 9 are kept in order. The four log lines now sit on consecutive rows with no padding.
What gets removed and what stays
| Line content | Trim result | Verdict |
|---|---|---|
hello world | hello world | Kept |
indented | indented | Kept (indent preserved) |
| empty string | empty string | Removed |
(three spaces) | empty string | Removed |
| tab + tab | empty string | Removed |
. (single dot) | . | Kept |
| non-breaking space U+00A0 | empty string | Removed (trim treats NBSP as whitespace) |
Common mistakes and pitfalls
- Running this on Markdown source. Blank lines separate paragraphs in Markdown; removing them merges paragraphs and breaks lists. Strip after render, never before.
- Stripping blanks from poetry or stanza-formatted text. The break is the format. Use a different cleanup or pick the survivors manually.
- Forgetting CRLF. The line ending changes to LF on output. Notepad and a few legacy Windows tools display LF-only files as one giant line; re-save as CRLF in your editor if needed.
- Using on YAML configs. Blank lines have no semantic meaning in YAML but section breaks help humans. Removing them works but the file becomes harder to read in code review.
- Assuming the row count for logging. The line numbers you see now will not match the original file once blanks are removed. Keep the unprocessed copy if you need to map line N back to a source.
- Pasting unicode whitespace. Trim now treats most Unicode whitespace (NBSP, zero-width space, em space) as blank, so lines that look indented can disappear. Inspect before publishing.
Related tools
Frequently asked questions
Does whitespace count as blank?
Yes. A line containing only spaces, tabs, or any mix of whitespace (including non-breaking spaces) is treated as blank and removed. The tool runs trim() on each line and drops it if the trimmed result is the empty string.
Will my line numbers shift?
Yes. If you remove blank lines, the surviving lines become consecutive, so any stack trace or compiler error tied to a numbered line will point to the wrong place. Keep the original file if you need to map errors back.
What about CRLF line endings?
CRLF (Windows) and LF (Unix) endings are both recognised on input, but the output is normalised to LF. Re-save with your editor's line-ending option if you need CRLF back for Notepad or legacy Windows tools.
Will it strip whitespace inside surviving lines?
No. Only fully blank lines are removed. The content of kept lines, including their leading and trailing whitespace, is untouched. Run a separate trim tool if you also want each line stripped.
Can I do this in a single line of vim?
Yes. The command :g/^\s*$/d removes every blank or whitespace-only line in the current buffer. Same effect as this tool. Use whichever is faster for the file you are in.
Will it work on Markdown?
It runs, but it will merge paragraphs because Markdown uses blank lines as the paragraph separator. The first blank line ends a paragraph; remove it and the next line is appended to the previous one on render. Strip blanks only after the Markdown is rendered to HTML, never before.
Does it preserve indentation?
Yes. Indentation is part of the line content, not part of the line break, so a kept Python or YAML line keeps its leading spaces or tabs exactly as you pasted them. This matters for whitespace-sensitive formats: stripping blanks does not corrupt indentation.
