Remove line breaks

Turns multi-line text into a single line while preserving words.

Overview

The line break seems like the simplest concept in the world until you try to understand how it actually works in detail. On Unix, a line break is the LF character (Line Feed, ASCII code 10). On Windows, it is the CR+LF sequence (Carriage Return plus Line Feed). On the old classic Mac OS, it was just CR. LF won as the universal internet standard: HTTP, SMTP, JSON, and most network protocols use LF or CR+LF as the line separator regardless of the server's operating system. This difference across systems is a constant source of frustration for developers in mixed environments — the classic case of a file that looks correct on macOS but opens as a single line in Windows Notepad.

The story of two characters to represent end-of-line comes from typewriters. The Carriage Return was the physical mechanism that pushed the carriage back to the start of the line. The Line Feed was the roller that advanced the paper to the next line. Early computer printers and terminals mimicked this mechanical behavior. When Ken Thompson and Dennis Ritchie created Unix, they decided a single character would be enough to mark end-of-line, simplifying the standard. Microsoft kept two characters in DOS and later Windows for compatibility, and maintains that tradition to this day.

Joining multiple lines into one is a practical necessity in several development situations. SQL queries formatted across multiple lines for readability need to be condensed into one line to be passed as a string in a shell script or environment variable. SSH private keys and TLS certificates stored in environment variables need their line breaks removed because many systems do not support multi-line values. JSON payloads that need to be included as a curl argument or as a value in a .env file also depend on a single continuous line to work correctly.

Technical deep dive

LF, CR and CRLF: the line ending wars

  • LF (\n, U+000A): Unix and Linux standard. Git, JSON, HTTP, and virtually all internet protocols use LF as the line terminator.
  • CRLF (\r\n, U+000D U+000A): Windows and DOS standard since CP/M in the 1970s. Many network protocols like SMTP and HTTP/1.1 specify CRLF in headers — which creates confusion when mixing message body and headers.
  • CR (\r, U+000D): classic Mac OS standard through version 9. Apple migrated to LF in OS X (2001). Still appears in some legacy files and Excel exports from older systems.
  • Git and the autocrlf setting: Git can automatically convert CRLF to LF on commit (core.autocrlf=true on Windows) to keep the repository using LF. This is essential in projects with collaborators on different systems.
  • Mixed line ending files: files that mix LF and CRLF in the same file are a real problem in CI/CD pipelines — some linting tools fail silently in these cases.

When you need a continuous single line

  • Environment variables: most operating systems and frameworks do not support line breaks in environment variable values. SSH private keys and JWT tokens stored in .env must be on a single line.
  • curl arguments: when passing a JSON payload as a -d argument, the shell interprets literal line breaks. The string must be a continuous line or properly escaped.
  • .env files: the standard dotenv format does not support multi-line values without special quoting. Certificates and keys inline in .env need their breaks removed.
  • SQL queries in shell scripts: when building queries dynamically in bash, line breaks in SQL strings can be misinterpreted by the shell or the database client.
  • HTTP headers via command line: HTTP headers cannot contain line breaks. An Authorization header value with a multi-line JWT token would fail silently or cause a parse error.

Tool guide

  • What line breaks are Delimiters (\n/\r\n) that split lines in text and logs.

  • What the tool does Replaces line breaks with spaces and normalizes extra spaces into one line.

  • Why use it Prepare payloads, environment variables, and fields that do not accept multi-line input.

Code Snippets

Remove line breaks in JavaScript
// Removes CRLF and LF, preserving words with spaces
const oneLine = text
  .replace(/\r\n/g, ' ') // CRLF first
  .replace(/[\r\n]/g, ' ') // then standalone CR and LF
  .replace(/  +/g, ' ') // collapse double spaces
  .trim();
Remove breaks into a compact string (no spaces between lines)
// Joins lines with no separator — useful for tokens, base64, hashes
const compact = text
  .replace(/\r\n|\r|\n/g, '') // remove any line ending style
  .trim();

Example

linha 1
linha 2 -> linha 1 linha 2

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.