Troubleshooting Line Ending Issues (CRLF vs LF)
Different operating systems use different line endings, causing text files to display incorrectly or break scripts. Learn how to detect and fix the issue.
Key Takeaways
- Windows uses CRLF (\r\n), Unix/macOS uses LF (\n), and old Mac Classic used CR (\r).
- Text appears as one long line (LF file opened on old Windows software).
- Look for `^M` characters at line ends in terminal editors.
- Convert CRLF to LF for Unix/macOS use.
- Configure Git to handle line endings consistently: `git config core.autocrlf true` on Windows, `git config core.autocrlf input` on macOS/Linux.
ๅญๆฐ็ป่ฎก
็ป่ฎกๅญๆฐใๅญ็ฌฆๆฐใๅฅๅญๆฐๅๆฎต่ฝๆฐใ
The Line Ending Problem
Windows uses CRLF (\r\n), Unix/macOS uses LF (\n), and old Mac Classic used CR (\r). When files move between systems, line endings can cause rendering problems and break scripts.
Symptoms
- Text appears as one long line (LF file opened on old Windows software).
- Extra blank lines appear between every line (CRLF on some Unix viewers).
- Shell scripts fail with
\r: command not founderrors. - Git shows every line as changed despite no content modifications.
Detection
Look for ^M characters at line ends in terminal editors. In a hex editor, CRLF shows as 0D 0A and LF shows as 0A. Many text editors show line endings in the status bar.
Fixing Line Endings
Convert CRLF to LF for Unix/macOS use. Convert LF to CRLF for Windows batch scripts. Most modern editors handle this automatically, but bulk conversion tools are needed for large file collections.
Git Configuration
Configure Git to handle line endings consistently: git config core.autocrlf true on Windows, git config core.autocrlf input on macOS/Linux. A .gitattributes file can enforce settings per file type.
็ธๅ ณๅทฅๅ ท
็ธๅ ณๆ ผๅผ
็ธๅ ณๆๅ
Text Encoding Explained: UTF-8, ASCII, and Beyond
Text encoding determines how characters are stored as bytes. Understanding UTF-8, ASCII, and other encodings prevents garbled text, mojibake, and data corruption in your applications and documents.
Regular Expressions: A Practical Guide for Text Processing
Regular expressions are powerful patterns for searching, matching, and transforming text. This guide covers the most useful regex patterns with real-world examples for common text processing tasks.
Markdown vs Rich Text vs Plain Text: When to Use Each
Choosing between Markdown, rich text, and plain text affects portability, readability, and editing workflow. This comparison helps you select the right text format for documentation, notes, and content creation.
How to Convert Case and Clean Up Messy Text
Messy text with inconsistent capitalization, extra whitespace, and mixed formatting is a common problem. This guide covers tools and techniques for cleaning, transforming, and standardizing text efficiently.
Troubleshooting Character Encoding Problems
Garbled text, question marks, and missing characters are symptoms of encoding mismatches. This guide helps you diagnose and fix the most common character encoding problems in web pages, files, and databases.