Line endings on different systems
| System | Line ending | Escape | Bytes |
|---|---|---|---|
| Linux, macOS, most tools | LF | \n | 0A |
| Windows, HTTP headers, CSV (RFC 4180) | CRLF | \r\n | 0D 0A |
| Classic Mac OS (before 2001) | CR | \r | 0D |
All three are recognised here. A file with CRLF endings shows up as ^M at the end of each line in Vim or cat -A on Linux.
Removing line breaks in code
tr '\n' ' ' < file.txt # every line break to a space
paste -sd, file.txt # join lines with commas
tr -d '\r' < windows.txt > unix.txt # CRLF to LF
one_line = " ".join(text.split()) # also collapses runs of spaces
# Keep paragraphs: join lines inside each blank-line-separated block
import re
paragraphs = re.split(r"\n\s*\n", text)
result = "\n\n".join(" ".join(p.split()) for p in paragraphs)
const oneLine = text.replace(/\s*\r?\n\s*/g, ' ').trim();
Removing blank lines but keeping the others? Use remove empty lines. Building a quoted list for SQL or JSON? Use the comma separated list converter.
Frequently asked questions
How do I keep paragraphs but remove the line breaks inside them?
Leave “Keep paragraph breaks” on, which is the default. Lines separated by a single line break are joined into one, and a blank line is treated as the end of a paragraph and kept. This is what you want for text copied from a PDF, an email or a terminal, where lines are wrapped at a fixed width.
Can I join lines with a comma instead of a space?
Yes. Type any separator in “Join with”: a comma and space, a semicolon, a pipe or nothing at all. Type \t for a tab. For quoted lists such as a SQL IN clause or a JSON array, the comma separated list tool also adds quotes and brackets.
Why does text copied from a PDF have line breaks everywhere?
A PDF doesn’t store paragraphs, only lines of text at positions on the page. When you copy, most viewers put a line break at the end of every visual line, so sentences are cut where the page wrapped them. Joining lines within paragraphs restores the flowing text.
What about words hyphenated at the end of a line?
They are joined with the separator like any other line, so “informa-” and “tion” become “informa- tion”. Use find and replace with the regex -\s+ to remove those hyphens afterwards, but check the result: real hyphenated words like “well-known” can also end up at a line break.