Remove empty lines

Drop empty lines or whitespace-only lines, keep the rest.

Overview

Empty lines are the invisible garbage of text files. They do not show as problems on screen, they carry no useful content, but they consume space, skew line counts, and become noise in code diffs and file comparisons. The problem is that the concept of empty is not universally agreed upon: a line with literally no characters before the line break is empty by any standard; but a line containing only spaces and tabs has no visible content and is usually equally unwanted.

The most common source of extra blank lines is pasting content from multiple origins. A paragraph copied from a website, a list pasted from a spreadsheet, a log excerpt pulled from a terminal — each source has its own convention for vertical spacing. The result is a text full of irregular gaps that make reading and processing harder than they need to be.

In command-line text processing, tools like sed and awk have had classic commands for this for decades — because the problem has existed for decades. In Python, a simple list comprehension with .strip() handles it in one expression. These patterns remain relevant every time someone pastes text from different sources.

Technical deep dive

What counts as an empty line

  • Completely empty line: the end-of-line sequence (LF, CRLF, or CR) appears immediately after another end-of-line. There is absolutely no character between the two breaks.
  • Whitespace-only line: contains one or more spaces, tabs, or other spacing characters, but no visible character. Visually indistinguishable from an empty line in most editors.
  • The option to strip whitespace-only lines removes lines containing only Unicode space characters (including non-breaking space, U+00A0), but preserves lines with any visible character.
  • End-of-file without a trailing newline: some editors add an implicit empty line at the end of a file. This is different from a real blank line and should generally not be removed.

Frequent use cases

  • Cleaning text copied from PDFs, which frequently introduces blank lines between paragraphs during extraction.
  • Normalizing INI, TOML, or properties config files that have accumulated blank lines through manual edits.
  • Preparing keyword or tag lists for automated processing, removing empty entries that would produce null elements when splitting by line.
  • Reducing log file size before emailing them or uploading to support tickets.
  • Eliminating double paragraph breaks in Markdown before converting to HTML, when the target format does not use extra spacing.

Tool guide

  • What you are working with Multi-line text.

  • What the tool does Removes completely empty lines and, optionally, lines that contain only spaces or tabs.

  • Why use it Tighten logs, poetry, pasted CSV, or any block where blank lines hurt processing or reading.

Code Snippets

Remove blank lines in JavaScript
// Remove completely empty lines
const result = text
  .split('\n')
  .filter(line => line.length > 0)
  .join('\n');

// Also removes whitespace-only lines
const resultTrim = text
  .split('\n')
  .filter(line => line.trim().length > 0)
  .join('\n');
Python one-liner
# Remove empty lines
result = '\n'.join(line for line in text.splitlines() if line)

# Remove whitespace-only lines too
result = '\n'.join(line for line in text.splitlines() if line.strip())

Before

a

  
b → a
b (com opção de ignorar só espaços)

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.