Remove Empty Lines

Delete blank lines, including lines that hold only spaces or tabs, while every line with content stays untouched and in order. Runs in your browser.

The interactive tool loads here when JavaScript runs.

About this tool

What is Remove Empty Lines?

Remove Empty Lines deletes every line that is empty or contains only whitespace (spaces, tabs or non-breaking spaces). Lines with any visible character are kept exactly as they are, including their own leading and trailing spaces, and in the same order.

Use it to compact a list that picked up gaps when copied from an email, a PDF or a web page, or to strip the blank separators from a log before counting lines.

There is no option to keep single blank lines between paragraphs: every blank line goes. Processing runs in your browser and nothing is uploaded.

  • Removes empty and whitespace-only lines
  • Leaves content lines byte-for-byte unchanged
  • Keeps the original order
  • Copy and Clear buttons
  • Runs in your browser; nothing is uploaded
Read the guide: Cleaning Up Text Lists: Spaces, Blank Lines, Duplicates and Commas

Updated

How to use Remove Empty Lines

  1. Paste your text into Input Text.
  2. Click Remove Empty Lines.
  3. Check Output Text, where only lines with content remain.
  4. Click Copy Result, or Clear to start again.

Worked example

Compacting a list with gaps

Input

line one

   
line two


line three

Output

line one
line two
line three

Both truly empty lines and the line that held three spaces are removed. The three content lines keep their order.

Background and insight

The shell equivalents are grep -v '^[[:space:]]*

#x27; or sed '/^[[:space:]]*$/d'. The pattern ^\s*$ is what defines "empty" here: a line from start to end that contains nothing but whitespace. A plain ^$ would miss lines that look empty but contain a stray space, which is the most common reason a blank-line filter appears not to work.

Blank lines are rarely meaningful in lists, but they are in prose and some formats. Markdown uses a blank line to separate paragraphs, so removing them merges paragraphs into one. YAML and many config formats ignore blank lines, but a few, such as HTTP messages and email headers, use the first empty line to mark where the body begins.

Common use cases

  • Compacting copied lists

    Remove the gaps that appear when a list is copied from an email, chat or PDF.

  • Counting real entries

    Strip blank lines so a line count reflects actual items, not separators.

  • Cleaning log excerpts

    Remove blank padding lines from logs before sharing them or feeding them to another tool.

  • Preparing data for import

    Make sure a one-value-per-line file has no empty records before importing it.

Tips and limitations

  • Markdown paragraphs are separated by blank lines. Removing them joins paragraphs, so do not run this on prose you want to keep formatted.
  • Content lines keep their own leading and trailing spaces. Run Remove Extra Spaces as well if you also want those trimmed.
  • If you need one blank line between blocks rather than none, this tool is too blunt; use a regex replace of \n{3,} with \n\n in a code editor instead.
  • Lines to Comma and Find Duplicate Entries already skip blank lines, so you do not need this step before them.

Sources and further reading

  1. GNU Grep manual, GNU Project. grep -v and anchored patterns such as ^[[:space:]]*$
  2. CommonMark Spec, CommonMark. Blank lines separate Markdown paragraphs
  3. RFC 9112: HTTP/1.1, IETF. An empty line ends the header section of an HTTP message
  4. RFC 5322: Internet Message Format, IETF. An empty line separates email headers from the body

Frequently asked questions

Does Remove Empty Lines also remove lines that only contain spaces?

Yes. A line counts as empty if it contains nothing but whitespace, which includes spaces, tabs and non-breaking spaces. That catches the "blank" lines that a simple ^$ search misses because they hold a stray space or tab copied along with the text.

Can I keep one blank line between paragraphs?

No, this tool removes every blank line. To collapse runs of blank lines into a single one, use a code editor with regex search and replace \n{3,} with \n\n, or the equivalent in your language of choice. That keeps paragraphs separate while removing the extra gaps.

Will removing empty lines change the content of other lines?

No. Lines with visible content are copied through exactly, including any indentation or trailing spaces they had. Only the empty and whitespace-only lines are dropped. Use Remove Extra Spaces separately if you want the remaining lines trimmed too.

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

Use find and replace with regular expressions on, search for ^\s*$\n (or ^\s*\r?\n for Windows files) and replace with nothing. Notepad++ also has Edit > Line Operations > Remove Empty Lines. Pasting here is quicker for text that is not already in a file.

Why does my line count drop after removing empty lines?

Because blank lines were counted as lines before. A list of 100 items with a blank line between each one has 199 lines; after cleaning it has 100. That makes the line count a reliable count of entries, which is often why people remove blank lines in the first place.

Is there an in-depth guide to Remove Empty Lines?

Yes. “Cleaning Up Text Lists: Spaces, Blank Lines, Duplicates and Commas” covers the background, how it works, common pitfalls and worked examples. Read the full guide.