Detect and Identify Line Ending Types (LF vs CRLF)
Detect whether your text uses Unix (LF), Windows (CRLF), or legacy Mac (CR) line endings. Identify mixed line endings that cause cross-platform issues.
Detailed Explanation
Understanding Line Endings
Different operating systems historically used different characters to mark the end of a line in text files:
- LF (Line Feed, \n, U+000A) — Unix, Linux, macOS (since OS X)
- CRLF (Carriage Return + Line Feed, \r\n, U+000D U+000A) — Windows
- CR (Carriage Return, \r, U+000D) — Classic Mac OS (pre-OS X)
How the Visualizer Shows Line Endings
The Whitespace Visualizer uses distinct markers for each type:
- LF appears as a green ↵ symbol
- CR appears as a green ← symbol
- CRLF appears as a green ←↵ combined symbol
The Line Endings section below the visualization provides a summary: "LF (15)" or "CRLF (15)" or "Mixed: LF (10), CRLF (5)".
Why Line Endings Matter
| Problem | Cause |
|---|---|
| Git shows entire file changed | Mixed line endings or wrong .gitattributes config |
| Shell script fails on Linux | CRLF endings from Windows: /bin/bash\r: bad interpreter |
| CSV parsing produces extra blanks | CRLF in CSV read by Unix tool adds phantom \r to last column |
| Docker build errors | Windows CRLF in shell scripts copied into Linux containers |
| CI pipeline failures | Scripts edited on Windows have CRLF, CI runs on Linux |
Normalizing Line Endings
To convert all line endings to LF (Unix standard):
- Paste the text and verify mixed endings in the statistics.
- In the Clean section, enable CRLF and CR toggles.
- Click Clean — the tool replaces CRLF with LF and removes standalone CR.
- Copy the normalized text.
For comparing text with different line endings, the Diff Viewer can highlight the differences.
Use Case
A DevOps engineer's Docker build fails because a shell script copied from a Windows machine has CRLF line endings. They paste the script into the Whitespace Visualizer, confirm mixed CRLF/LF endings, clean to LF only, and the Docker build succeeds.