We've all been there. You copy some text from a PDF, an email, or a document, paste it somewhere, and suddenly it's broken into awkward short lines that interrupt the flow. Or maybe you're building something and the newlines in your text are breaking your layout, your database query, or your API call.
Let's look at the best ways to fix this.
Why Do Unwanted Line Breaks Happen?
Line breaks sneak in from a few common places:
- PDFs — most PDF readers break text based on the visual layout of the page, not the actual sentence structure
- Email clients — many email programs wrap long lines at 72 or 80 characters for historical reasons
- Old documents — Word documents and older CMS exports sometimes hard-wrap paragraphs
- Markdown editors — some create a line break for every visual line, even within a paragraph
- System differences — Windows uses
\r\n, Unix uses\n, and old Macs use\r, causing issues when mixing systems - Press
Ctrl+H(orCmd+Hon Mac) to open Find & Replace - In the "Find what" field, type
^p(paragraph mark) or^l(manual line break) - In "Replace with", type a space or leave blank
- Click Replace All
- Press
Ctrl+H - Enable "Regular expressions" (click the
.*icon) - Search for
\nand replace with a space - Code: never remove line breaks from code — they define structure
- Addresses: lines separate street, city, zip — removing them loses context
- Tables: line breaks define rows
- Verse/Poetry: breaks are intentional
Method 1: Use an Online Tool (Fastest)
For a one-off cleanup, an online line break remover is the quickest option. Our Remove Line Breaks tool does it in literally one click.
How it works:
1. Paste your text into the left panel
2. Choose your replacement mode (space, nothing, custom character, or just remove extras)
3. Copy the result from the right panel
The tool handles all line ending formats (\n, \r\n, \r) and gives you the result instantly as you type.
Method 2: Find & Replace in Word or Google Docs
In Microsoft Word:
In Google Docs:
Method 3: Excel or Google Sheets
If you have text in a cell, use the SUBSTITUTE function:
`` =SUBSTITUTE(A1, CHAR(10), " ")
`
This replaces all newline characters (CHAR(10)) with a space. For carriage returns use CHAR(13).
Method 4: Using Code
For developers who need to handle this programmatically:
JavaScript:
`javascript
const cleaned = text.replace(/[\r\n]+/g, ' ');
`
Python:
`python
cleaned = text.replace('\r\n', ' ').replace('\n', ' ').replace('\r', ' ')
`
PHP:
`php
$cleaned = str_replace(["\r\n", "\r", "\n"], " ", $text);
`
Method 5: Command Line
If you're on a Unix-like system (Mac or Linux):
`bash
Remove all line breaks
tr -d '\n' < input.txt > output.txt
Replace line breaks with space
tr '\n' ' ' < input.txt > output.txt
`
Choosing the Right Replacement
What should you replace line breaks with? Here are the most common scenarios:
| Your goal | Replace with |
|-----------|-------------|
| Merge into one text block | A single space |
| Create comma-separated list | , ` |
| Remove line breaks completely | Nothing (empty string) |
| Keep paragraph structure | Leave mode as "remove extra only" |
When NOT to Remove All Line Breaks
Be careful: sometimes line breaks are meaningful.
In these cases, use the "Remove Extra Blank Lines Only" mode, which collapses multiple empty lines into one but preserves single line breaks.
Try It Now
No installation, no account. The Remove Line Breaks tool is ready to use right now in your browser.