usefmtly

How to Remove Line Breaks

Copying text from PDFs, Word documents, and emails almost always leaves unwanted line breaks. Here is why it happens and how to fix it.

Why pasted text has line breaks

A line break is a character that tells software to start a new line. When you copy text from a source that has a fixed visual layout, those layout boundaries travel with the text as line-break characters. The result is pasted text that looks like a poem instead of a paragraph.

PDF documents

PDFs store text in fixed-layout blocks. Each line of the original layout becomes a separate text element. When you copy and paste, those layout boundaries become newline characters in your clipboard.

Microsoft Word

Word uses its own paragraph and line-break characters. When pasted into a plain text field, soft returns (Shift+Enter) become line breaks that do not belong in continuous prose.

Email clients

Many email systems wrap long lines at 72–80 characters for display purposes. When you copy email body text, those display wraps come along as hard newlines.

OCR output

Optical character recognition software converts each scanned line into a text line. The result looks fine on screen but has a line break after every visual row of the original document.

Command-line output

Terminal output wraps at the terminal window width. Copying from a terminal picks up those wraps as newlines regardless of where sentences actually end.

Types of line breaks

Not all line breaks are the same character. Understanding the types helps when choosing how to clean them up.

TypeCharactersOrigin
LF (Line Feed)\nUnix, Linux, macOS (current)
CR (Carriage Return)\rOld Mac (pre-OS X)
CRLF\r\nWindows, older internet protocols
Hard return↵ (paragraph mark)Word processors — ends a paragraph
Soft return↵ (line break)Word Shift+Enter — line break within a paragraph

Which cleanup do you need?

Remove all line breaks (join into one paragraph)

When: You copied a paragraph from a PDF and each line is separate. You want one continuous paragraph.

How: Replace every newline with a single space.

Remove only extra blank lines (keep paragraph breaks)

When: You have a document with multiple paragraphs separated by double line breaks, but also stray single line breaks inside paragraphs.

How: Replace single newlines inside paragraphs with spaces, preserve double newlines as paragraph separators.

Normalize line endings

When: A file uses mixed Windows (CRLF), Mac (CR), and Unix (LF) line endings — causing display issues across systems.

How: Standardize all line endings to LF (Unix) or CRLF (Windows) depending on the target system.

Remove blank lines only

When: Your text has multiple empty lines between content. You want to collapse them without touching the content itself.

How: Remove lines that contain only whitespace.

When to keep line breaks

Not every line break should be removed. There are cases where they are structurally important:

  • Poetry and lyrics — line breaks are part of the meaning and should be preserved exactly.
  • Code — indentation and line structure matter. Never strip line breaks from source code.
  • Addresses — street, city, and country are typically on separate lines intentionally.
  • Numbered or bulleted lists — each item should stay on its own line.
  • CSV data — each row is a line; removing breaks destroys the structure.

The rule of thumb: remove line breaks when the source format introduced them artificially (PDF layout, email wrapping, terminal output). Keep them when the author placed them intentionally.

How to do it manually

In most text editors and word processors, you can use Find & Replace to remove line breaks:

Microsoft Word

Open Find & Replace (Ctrl+H). In "Find what", type ^p (paragraph mark) or ^l (manual line break). In "Replace with", type a space. Click Replace All.

Google Docs

Use Find & Replace (Ctrl+H). Check "Regular expressions". In "Find", type \n. In "Replace with", type a space. Click Replace all.

VS Code

Open Find & Replace (Ctrl+H). Enable regex mode (Alt+R). In "Find", type \n. In "Replace", type a space or leave empty. Click Replace All.

Notepad++

Find & Replace (Ctrl+H). Set "Search Mode" to Extended or Regular expression. Search for \r\n or \n, replace with a space.

Beyond line breaks — other text noise to clean

When fixing pasted text, line breaks are often not the only problem. Other common issues that appear together:

  • Double spaces — appear between words when line breaks were replaced with spaces.
  • Smart quotes — curly “ ” ‘ ’ copied from Word or web pages may not paste cleanly into plain text systems.
  • Non-breaking spaces — invisible characters ( ) that look like spaces but behave differently in code.
  • Hyphenated words split across lines — PDFs often hyphenate long words at line ends. After removing breaks, you get words like “un-” + “fortunately” as “un- fortunately”.
  • HTML tags — copying from web pages sometimes brings <br>, <p>, or <span> tags along.

Free tools for this