How to Remove Line Breaks From Text and Keep Paragraphs
To remove line breaks from copied text without losing your paragraphs, replace only the single line breaks with a space and leave the blank lines alone. A blank line is really two line breaks in a row, so it survives as long as your method can tell one break from two.
The order of the cleanup matters as much as the replacement itself. Before joining anything, clear out page numbers and headers, normalize line endings, rejoin hyphenated words, and protect any lists. If you join lines too early, you can end up with errors like "infor- mation" or a shopping list squeezed into one sentence.
This guide explains where the extra breaks come from, shows a full before-and-after example, and gives you three ways to do the job: an online tool, Microsoft Word, and regular expressions.
Why copied text has a line break at the end of every line
The breaks look the same wherever you paste them, but they have different causes. Knowing the source tells you what other damage to look for.
PDFs. A PDF mainly records where text sits on a page, not how it flows from one line to the next. When you copy from one, the reader app has to work out the lines and paragraphs from their positions, and it often ends each visual line with a break. Results vary by PDF and reader, and some files carry structure tags that help.
Emails. Plain-text email has a long history of hard wrapping. The email format standard, RFC 5322, says lines should be no longer than 78 characters and must not exceed 998, so many mail programs break long lines before sending. A separate convention called format=flowed marks these wraps as "soft" so that supporting mail apps can rejoin them, but a forwarded or quoted message can still arrive with fixed breaks.
Old documents and plain text files. Older text files were often wrapped by hand or by software to fit a fixed width, commonly around 70 to 80 characters. Text produced by OCR (optical character recognition, which turns images of pages into text) usually keeps the line structure of the scanned page as well.
In every case, the break records where a line ended on a page or screen, not where a thought ended.
Before and after: what good cleanup looks like
Here is a typical passage pasted from a PDF. It has three paragraphs, a hyphenated word, and a bulleted list with one wrapped item.
Good records make audits faster because each infor-
mation request points to a single source. Staff
spend less time searching.
Before the audit, gather:
• signed contracts
• bank statements for the
last two years
• a list of current vendors
Send the files by Friday. Late submissions
may delay the review.
If you simply replace every line break with a space, you get this:
Good records make audits faster because each infor- mation request points to a single source. Staff spend less time searching. Before the audit, gather: • signed contracts • bank statements for the last two years • a list of current vendors Send the files by Friday. Late submissions may delay the review.
That one replacement causes four separate problems:
- The paragraph breaks are gone.
- "information" has become "infor- mation".
- The list has collapsed into one line.
- Two spaces sit where each blank line was, and three sit before "last".
This is the result you want:
Good records make audits faster because each information request points to a single source. Staff spend less time searching.
Before the audit, gather:
• signed contracts
• bank statements for the last two years
• a list of current vendors
Send the files by Friday. Late submissions may delay the review.
Notice that the wrapped bullet was joined, but the bullets themselves stayed on separate lines.
How to remove line breaks but keep paragraphs
Choose a method based on how much text you have and how often you do this.
| Method | Best for | Main trade-off |
|---|---|---|
| Online tool | Quick, one-off cleanup | Check paragraphs, lists, and hyphens in the output, and prepare the text first if needed |
| Microsoft Word | Occasional use, with review as you go | Takes several replace passes |
| Regex in a code editor or script | Repeated jobs, many files | Requires care, and a wrong pattern can change a lot of text at once |
Use an online tool
If your source is a PDF, start with the PDF to Text converter to extract the text, then copy it or save it as a TXT file. For a long file, you can extract just the pages you need first so there is less to review.
Then use the Line Break Remover, which removes line breaks and extra spaces from text copied from PDFs. Don't assume it will keep blank-line paragraphs, rejoin split words, or hold list items apart. Try a short sample containing all three first, and look for any options that control them.
If the sample comes back as one block, prepare the text with placeholders, which pass through as ordinary characters:
- Rejoin hyphenated words by hand.
- Type
@@@on each blank line and###at the start of each list line. - Run the text through the tool.
- In Word or another editor, replace
@@@with a blank line and###with a line break, then remove any stray spaces beside them.
For a short text, it can be simpler to run one paragraph at a time and add the blank lines back yourself.
Use find and replace in Microsoft Word
Word's replace dialog (Ctrl+H on Windows) has long used ^p for a paragraph mark. The trick is to hide real breaks behind two placeholders that appear nowhere in your text, such as @@@ for paragraphs and ### for list lines. Keep "Use wildcards" turned off, then work through these steps in order:
- Paste the text into a blank document using the Keep Text Only option. With a formatted paste, bullets can become list formatting that a text search won't find.
- Click Show/Hide (¶) to see which breaks you have. A ¶ is a paragraph mark, and a bent arrow is a manual line break. If
^pfinds nothing, your breaks may be manual line breaks. Use^lin place of^pin every Find box below, then restore them with^p. If you see both kinds, replace^lwith^pfirst. - Replace
^p^pwith@@@. This protects the blank lines. - Replace
^p•with###•. Copy the bullet from your own text into the Find box so it matches exactly. For numbered lists, run one pass per number: replace^p1.with###1., then^p2.with###2., and so on. The^#code won't shorten this, because it can find a digit but can't put that same digit back. - Find
-^pand step through the matches, deleting the break and hyphen only where a word was split. - Replace
^pwith a single space. This joins the wrapped lines. - Replace
@@@with^p^pto restore paragraphs. - Replace
###with^pto restore the list lines. - Replace two spaces with one, and repeat until Word finds no more matches.
Use regular expressions
A regular expression, or regex, is a search pattern that can describe things like "a line break not followed by another line break." This short Python function applies the steps in a safe order:
import re
def unwrap(text):
text = re.sub(r"\r\n?", "\n", text) # 1. one line-ending style
text = re.sub(r"[ \t]+\n", "\n", text) # 2. trailing spaces
text = re.sub(r"(?<=[a-z])-\n(?=[a-z])", "", text) # 3. hyphenated words
text = re.sub(r"(?<!\n)\n(?!\n|[ \t]*(?:[-*•]|\d+[.)])[ \t])", " ", text) # 4. single breaks
text = re.sub(r"[ \t]{2,}", " ", text) # 5. extra spaces
text = re.sub(r"\n{3,}", "\n\n", text) # 6. extra blank lines
return text.strip()
To run it on a UTF-8 file and print the result, add this line below the function, using your own file name:
print(unwrap(open('input.txt', encoding='utf-8').read()))
Step 4 does the main work. It matches a line break only when the previous character is not a break, the next character is not a break, and the next line does not start with a bullet or a number like "1." or "2)". Run on the sample above, this function produces the clean version shown earlier.
If you'd rather not use a script, many code editors have a regex mode in find and replace. In an editor that supports lookbehind, paste the step 4 pattern and replace it with a single space:
(?<!\n)\n(?!\n|[ \t]*(?:[-*•]|\d+[.)])[ \t])
Try it on a copy first. Convert the file to LF endings if your editor allows it, and run the patterns from steps 2 and 3 before this one and the step 5 pattern after it.
How to fix hyphenated words and collapsed lists
These two problems need attention before the join, because the evidence disappears once the lines run together.
Words hyphenated across lines
Rejoining "infor-" and "mation" means deleting the hyphen and the break together. Do this before joining lines, because afterward the pattern is "hyphen, space, letter," which also appears in legitimate phrases like "pre- and post-treatment."
There is one catch: not every hyphen at a line end was added by line wrapping. A true compound such as "well-known" may also break after its hyphen, and an automatic rule would turn it into "wellknown." Plain text doesn't record which kind you have, so a careful pass needs a dictionary or a human eye. After an automatic pass, a spell check will catch most bad merges.
Also watch for look-alike characters. Some PDFs produce a soft hyphen (U+00AD, an invisible marker for an optional break) or the Unicode hyphen (U+2010) instead of the keyboard hyphen. If your rule misses words that are clearly split, widen it to match those too. In the Python above, change the - just before \n in step 3 to [-‐], so the full line reads:
text = re.sub(r"(?<=[a-z])[-‐]\n(?=[a-z])", "", text) # 3. hyphenated words
Bulleted and numbered lists
Lists collapse because a list item ends with the same character as a wrapped line. The most useful clue is at the start of the next line: if it begins with a marker such as •, -, *, 1., or 2), keep the break in front of it. A wrapped item's second line has no marker, so it joins the line above, which is the behavior you want.
This rule can misfire on prose. In the text below, the second line begins with what looks like a numbered item:
The company opened its first office in
2019. Sales grew the next year.
A marker rule would keep this break, leaving the sentence split. Scan for lines that begin with a number after you finish, especially in text with many dates or figures.
When paragraphs have no blank lines between them
Many PDFs separate paragraphs with spacing or indents that often don't survive copying, so every break is a single break. A find-and-replace rule then has nothing to work with and merges the whole passage into one block.
Two clues can help you mark paragraph ends before you join anything:
- Short last lines. A line much shorter than its neighbors that ends in a period, question mark, or colon usually closes a paragraph.
- Indented first lines. A line starting with spaces can open a new paragraph. This only helps when indents were preserved, and wrapped list items can be indented too.
Add a blank line at each of those spots first, then run your usual method. Short lines can also occur for other reasons, so review these by hand.
Windows (CRLF) vs Unix (LF) line endings
A line break isn't always the same character. Windows text files traditionally end each line with two characters, while Linux and macOS use one.
| Style | Characters | Regex form | Where you see it |
|---|---|---|---|
| CRLF | Carriage return + line feed | \r\n |
Windows text files, email messages |
| LF | Line feed | \n |
Linux, macOS, and most Unix tools |
| CR | Carriage return | \r |
Classic Mac OS files from before OS X |
These endings look identical on screen but affect cleanup in three ways:
- Blank-line searches can fail. In CRLF text, a blank line is
\r\n\r\n, so a search for\n\nfinds nothing. Your rule may then treat every break as a single break and erase your paragraphs. - Stray characters can stay behind. Replacing only
\nwith a space leaves each\rin the text. It's usually invisible, but it can cause odd behavior in spreadsheets, scripts, and data imports. - Character counts change. Ten lines ending in CRLF contain 10 × 2 = 20 line-ending characters, while the same lines in LF contain 10 × 1 = 10. The text looks the same, yet its count differs by 10.
The fix is to convert all endings to \n before you join anything, as step 1 of the Python function does. Editors handle this differently, and some hide the distinction in regex mode, so test on a small sample if your pattern finds too much or too little.
Double spaces and other leftovers to clean up
Joining lines often leaves spacing problems behind. Each has a slightly different cause.
- Double spaces. These come from trailing spaces at line ends, indented continuation lines, and blank lines replaced with spaces. Collapse any run of two or more spaces into one as a final step. Skip this for code or text aligned in columns, where the spacing carries meaning.
- Lines that only look blank. A line containing a single space isn't truly empty, so it can defeat a blank-line rule. Strip trailing spaces before you join lines, as step 2 of the script does.
- Non-breaking spaces. The character U+00A0 looks like a normal space, but step 5 of the script won't match it, and some apps' searches won't either. If a double space refuses to go away, search for
^sin Word, or addtext = text.replace(" ", " ")before step 2 of the script, then collapse spaces as usual. This also converts any non-breaking spaces placed deliberately. - Page headers, footers, and page numbers. Text from a multi-page PDF can have "Page 12" or a chapter title in the middle of a sentence. Delete these before joining, because they're harder to spot once they're inside a paragraph.
- Scrambled columns. Two-column layouts may copy in the wrong order. No line break rule can repair that, so fix the order first or copy one column at a time.
Quick checklist for clean results
Use this general order. The Word method sets its placeholders before the hyphen pass, which works just as well, because what matters is that every protective step comes before the join.
- Delete page numbers, repeated headers, and footers.
- Convert line endings to one style, and strip trailing spaces.
- Check whether blank lines separate paragraphs. If they don't, add them.
- Rejoin words split by a hyphen, then spell-check for bad merges.
- Protect lines that start with bullets or numbers.
- Replace the remaining single breaks with a space.
- Collapse extra spaces, and reduce multiple blank lines to one.
- Compare the first and last paragraphs with the source, along with any lists.
Frequently Asked Questions
How do I remove line breaks inside an Excel cell?
Use a formula such as =SUBSTITUTE(A1,CHAR(10)," "), which replaces each line feed in cell A1 with a space. Copy the results and paste them as values if you want to replace the original text. If stray characters remain, the data may also contain carriage returns, which are CHAR(13).
What is the difference between a line break and word wrap?
A line break is an actual character stored in the text, while word wrap is only how an app displays long lines to fit the window. To tell them apart, make the window narrower or wider. Lines that reflow to fit are wrapped, and lines that keep ending at the same word have real breaks.
When should I keep line breaks instead of removing them?
Keep them in code, poetry, song lyrics, mailing addresses, and tables or data files where each line is a separate record. In these cases, the break carries meaning, and joining lines can change or destroy the content. Work on a copy if you're unsure, so you can compare it with the original.
Can I remove line breaks from a scanned PDF?
Not until the scan has been converted to text, because a scanned page without a text layer is essentially an image. You'll need to run OCR first, then clean up the output as you would any other copied text. Check OCR results carefully, since they can also contain misread characters that line break cleanup won't fix.
Why did my text become one giant paragraph?
Usually, the source had no true blank lines, or the blank lines contained spaces or CRLF endings that your search didn't match. Go back to the original text, convert the line endings, and strip trailing spaces. If there are still no blank lines, add them at paragraph ends before joining the lines.