Back to Blog

How to Remove Line Breaks from Text (7 Methods That Actually Work)

ToolsForTexts TeamUpdated April 9, 20266 min read
πŸ”§

Free Tool

Remove Line Breaks β€” Clean Up Text Online

Remove or replace line breaks, carriage returns, and extra blank lines from text instantly. Free online line break remover tool.

β†’

You copy some text from a PDF, an email, or a scanned document β€” and when you paste it somewhere else, it's broken into awkward short lines that interrupt the flow completely. Or you're building something and newlines in text are breaking your layout, your API request, or your database insert.

Let's look at every method for fixing this, from the fastest one-click solution to language-specific code snippets.

Why Do Unwanted Line Breaks Appear?

Line breaks sneak into text from several common sources:

  • PDFs β€” most PDF readers split text based on the visual page layout, not sentence structure
  • Email clients β€” many wrap long lines at 72 or 80 characters for historical reasons
  • Old documents β€” Word files and older CMS exports sometimes hard-wrap paragraphs
  • Markdown editors β€” some insert a line break for every visible line, even inside a single paragraph
  • System differences β€” Windows uses \r\n, Unix uses \n, and old Mac OS used \r. Mixing systems causes chaos

Method 1: Online Tool β€” Fastest (No Code, No Install)

For a quick cleanup, an online line break remover is the fastest approach. The Remove Line Breaks tool on ToolsForTexts handles it in one click:

  • Paste your text into the input panel
  • Choose your replacement mode: replace with a space, remove completely, or use a custom character
  • The output appears instantly as you type β€” no button needed
  • Copy the cleaned result to your clipboard

It handles all line ending formats (\n, \r\n, \r) and strips them all at once.

πŸ”§Remove line breaks from your text β€” free, instant, no signupβ†’
[@portabletext/react] Unknown block type "adBanner", specify a component for it in the `components.types` prop

Method 2: Find & Replace in Word or Google Docs

Microsoft Word

Press Ctrl+H (or Cmd+H on Mac) to open Find & Replace. In the 'Find what' field, type ^p for paragraph breaks or ^l for manual line breaks. Leave 'Replace with' empty or type a space. Click Replace All.

Google Docs

Press Ctrl+H, enable 'Regular expressions' (the .* icon), search for \n, and replace with a space.

Method 3: Excel or Google Sheets

If your text lives in a spreadsheet cell, use the SUBSTITUTE function with CHAR(10) β€” the character code for a newline:

1=SUBSTITUTE(A1, CHAR(10), " ")

For carriage returns (Windows line endings), use CHAR(13). For both at once, nest the functions:

1=SUBSTITUTE(SUBSTITUTE(A1, CHAR(10), " "), CHAR(13), "")

Method 4: JavaScript

This single regular expression handles all line ending formats at once:

1// Replace all line breaks with a space
2const cleaned = text.replace(/[\r\n]+/g, ' ');
3
4// Or remove them completely
5const noBreaks = text.replace(/[\r\n]+/g, '');
6
7// Or collapse multiple line breaks but keep single ones
8const collapsed = text.replace(/\n{3,}/g, '\n\n');

Method 5: Python

1# Replace all line breaks with a space
2cleaned = text.replace('\r\n', ' ').replace('\n', ' ').replace('\r', ' ')
3
4# Or use regex for a cleaner one-liner
5import re
6cleaned = re.sub(r'[\r\n]+', ' ', text)
7
8# Remove completely
9no_breaks = re.sub(r'[\r\n]+', '', text)

Method 6: PHP

1<?php
2// Replace all line endings with a space
3$cleaned = str_replace(["\r\n", "\r", "\n"], " ", $text);
4
5// Or use regex
6$cleaned = preg_replace('/[\r\n]+/', ' ', $text);
7?>

Method 7: Command Line (Mac / Linux)

1# Remove all line breaks
2tr -d '\n' < input.txt > output.txt
3
4# Replace line breaks with a space
5tr '\n' ' ' < input.txt > output.txt
6
7# Handle both \r\n and \n
8tr -d '\r' < input.txt | tr '\n' ' ' > output.txt

Choosing the Right Replacement

What you replace line breaks with depends on your use case:

  • Merging into one paragraph β†’ replace with a single space
  • Creating a comma-separated list β†’ replace with ,
  • Removing completely for JSON/API values β†’ replace with nothing
  • Keeping paragraph structure β†’ use 'Remove Extra Only' mode to collapse multiple breaks into one

When NOT to Remove All Line Breaks

Be careful β€” sometimes line breaks are meaningful:

  • Code: never remove line breaks from code. They define structure and logic.
  • Addresses: lines separate street, city, and zip. Removing them loses that structure.
  • Tables in plain text: line breaks define rows.
  • Poetry or verse: every break is intentional.

In these situations, use the 'Remove Extra Blank Lines Only' mode instead of removing all breaks.

Frequently Asked Questions

What is the difference between \n and \r\n?

\n (LF) is a Unix/Linux/Mac line ending. \r\n (CRLF) is a Windows line ending. Both appear as a line break on screen but are different characters. The online tool strips both automatically.

Why does pasting from a PDF add extra line breaks?

PDFs store text as positioned characters on a visual canvas, not as flowing paragraphs. When you copy from a PDF, the reader inserts a line break wherever the text visually wraps β€” regardless of where sentences actually end.

Can I remove line breaks from just part of my text?

Yes β€” select only the portion you want to process before pasting into the tool. Or use Find & Replace in your editor with a selection-limited scope.

Wrapping Up

Unwanted line breaks are one of the most common and most annoying text formatting problems. Whether you prefer a one-click online tool, a spreadsheet formula, or a code snippet, you now have the right approach for every situation.

πŸ”§Remove line breaks from your text β€” free and instantβ†’
πŸ”§

Free Tool

Remove Line Breaks β€” Clean Up Text Online

Remove or replace line breaks, carriage returns, and extra blank lines from text instantly. Free online line break remover tool.

β†’
text processingproductivityline breaksdeveloper tools