Fix mixed line endings in CSV
CRLF and LF mixed in the same file breaks parsers, splits rows incorrectly, and causes "unclosed quote" errors. Upload your CSV — CSViser detects the problem and normalises all line endings in one click.
Upload your CSV with mixed line endings
CSV, XLSX, or JSON — any size
Free account — takes 10 seconds to sign up
After upload: go to Fix issues tab → check Normalize line endings → Apply.
What are line endings and why do they get mixed?
Every line in a text file ends with an invisible character (or pair of characters) that marks
where the next line begins. Windows uses CRLF (\r\n, two bytes:
carriage-return + line-feed). Unix and macOS use LF (\n, one
byte: line-feed only). RFC 4180 mandates CRLF for CSV, but most real-world files use LF.
Mixed line endings appear when files are combined from different sources: you concatenate a
Windows export with a Unix export, a script processes a file and rewrites some rows with the
wrong style, or a copy-paste operation introduces the wrong characters. The result looks
identical in a text editor (which hides line endings), but parsers that read byte-by-byte
see \r characters appearing mid-row and miscount columns.
How mixed line endings break CSV parsers
A CSV parser that expects \n as the row delimiter will, on a CRLF row, consume
the \r as part of the last field value — so the final column of every row gains
a trailing \r. A parser that expects CRLF and encounters a bare \n
inside a quoted multi-line field may treat it as a row break. The specific failure mode
depends on the parser, but common symptoms are:
- Last column of every row has a trailing
\rcharacter - Row counts are wrong (extra empty rows or missing rows)
- "Unclosed quote" errors on rows that contain quoted multi-line text
- Misaligned columns after the first occurrence of a mixed ending
How CSViser detects and fixes this
CSViser uses a quote-aware scanner that strips quoted field content before counting
line-ending styles — this avoids false positives from multi-line text fields that legitimately
contain bare \n inside double quotes (which is valid per RFC 4180). Only actual
row delimiters are inspected. If both \r\n and bare \n are found
outside of quoted spans, the file is flagged as having mixed line endings.
The fix normalises all row delimiters to \n (LF), which is accepted by
virtually all modern parsers. The file content and column structure are unchanged — only
the row-terminator bytes are standardised.
Quick fix in Python or shell
# Python
with open("data.csv", newline="") as f:
content = f.read()
content = content.replace("\r\n", "\n").replace("\r", "\n")
with open("data_fixed.csv", "w", newline="") as f:
f.write(content)
# sed (macOS / Linux)
sed 's/\r//' data.csv > data_fixed.csv
Frequently asked questions
How do I know if my file has mixed line endings?
Open the file in a hex editor or run cat -A data.csv | head on Linux/macOS —
CRLF rows end with ^M$, LF rows end with just $. Or upload to
CSViser — the validator reports "mixed line endings" in the Fix issues tab if the problem
is present.
Does fixing line endings change the data?
No. Only the invisible row-terminator bytes change. All cell values, column headers, and field counts remain identical.
My CSV has multi-line text in quoted fields — is that safe?
Yes. CSViser's quote-aware parser preserves bare \n inside quoted fields
(which is valid per RFC 4180). Only row-level delimiters outside of quoted spans are
normalised.