Remove Empty Lines
Published Updated
Delete every blank or whitespace-only line and trim the spaces around each remaining line, with counts of both. Trimming also strips indentation, so an indented return statement loses its spaces, and a line with only a zero-width space is not blank to it.
Two switches, four outcomes
The test input had six lines: a padded with two spaces on each side, an empty line, a line of three spaces, a tab followed by b, and two empty lines.
| Remove empty | Trim | Output |
|---|---|---|
| On | On | a and b, each flush left; 4 lines removed, 2 trimmed |
| On | Off | Two spaces, a, two spaces, then a tab and b; whitespace kept |
| Off | On | Blank lines stay but become empty; line contents trimmed |
| Off | Off | Nothing changes except line endings |
What the page treats as blank
The test is JavaScript's trim, which MDN defines as removing white space characters plus line terminators. In practice that covers ordinary whitespace and the non-breaking space. A line holding only a non-breaking space was deleted in the test. A line holding only U+200B stayed, because that character is not whitespace to the language. If that is your case, run the text through AI Text Cleaner first.
Indentation is the cost of trimming
Text with a def line, an empty line and an indented return 1 came out as two lines, def f(): and return 1, with the indent gone and two items counted as removed or trimmed. Trimming is aimed at pasted prose, tables and lists. For anything where leading spaces carry meaning, untick it and keep only the blank-line removal.
Deleting blank lines
Step 1
Paste the text
Both switches start on. Line endings are converted to plain line feeds in the output.
Step 2
Set the switches
Remove empty lines and Trim whitespace work separately. Turn trimming off to keep indentation.
Step 3
Copy Result
Four counts show total lines, remaining lines, empty lines removed and lines trimmed.
Things to watch
- Trimming applies to all lines, not only blank ones, and is counted in Lines Trimmed.
- Tabs used as column separators inside a line are kept, since only the ends are trimmed.
- For repeats rather than blanks, Duplicate Line Remover is the one to use, and Word Counter gives totals afterwards.
Blank line questions
Can I keep one blank line between paragraphs?
No. Every empty line is removed, paragraph breaks included. To collapse runs of blanks into one, you need a different tool.
Does trimming break code?
It can. Trimming removes leading spaces on every line, so def f(): and an indented return 1 came out with the return flush left. Switch trimming off for Python, YAML or Markdown lists.
What counts as an empty line?
A line that is empty or holds only whitespace as JavaScript defines it: spaces, tabs and the non-breaking space all qualify. A line holding only U+200B, the zero-width space, does not.
My blank lines will not go away. Why?
They probably hold an invisible character such as a zero-width space. AI Text Cleaner removes those, after which this page deletes the lines.
Does it change the line endings?
Yes. CRLF and lone CR become LF, so a Windows file comes back with Unix endings.
Is the text uploaded?
No. The lines are filtered in the page and stay in your tab.