Practical guide

Handle commas, quotes and line breaks in CSV

Read a tricky record correctly instead of splitting on every comma.

Quick answer. Parse quoted CSV records before splitting or removing lines. A comma inside quotes is field content, doubled quotes represent one quote, and a quoted line break can stay inside one logical record.

Try a file with a known result

Original synthetic teaching data; no customer records. Download the small sample, then load it into the matching tool. Your own files remain in your browser.

Settings for this example

Load the sample in CSV check & repair, select Comma and keep the header on. Preview the complete file, including the final quoted field.

Expected results to compare

  1. The result has 3 data records and 2 columns, although the last note spans two physical lines.
  2. The first note is Notebook, blue and the second is He said "ready". Neither punctuation mark creates an extra field.
  3. The final note contains First line followed by a line break and Second line in the same field. Re-import a CSV export to compare parsed values; CRLF bytes may differ from another exporter.

Do not remove a quote merely because it looks unusual. An unmatched quote is an error; valid surrounding and doubled quotes are necessary structure.

Open the matching tool →

A comma does not always end a field

CSV is simple text, but splitting each line on commas is not a reliable parser. A field may contain its own comma, quotation mark or line break. RFC 4180 describes enclosing such fields in double quotes and doubling a quote that belongs inside the field.

id,note
00127,"Notebook, blue"
00904,"He said ""ready"""
00008,"First line
Second line"

There are four logical records here: a header and three data records. There are five physical text lines. The final note spans two physical lines but remains one field in one record.

Read the example as a table

The first note is Notebook, blue, including its comma. The second note is He said "ready", including the quotes. The third note retains the line break between its two sentences. Quoting is structure around the field; doubled quotation marks represent content inside it.

Preview before an export

  1. Copy the complete example into either TableMender tool.
  2. Select comma as the input delimiter and keep the header option checked.
  3. Preview. The data-record count should be three and the column count two.
  4. Inspect the notes. They should not become extra columns or separate records.

Try it in the converter →

A strict error can be useful

An opening quote without a closing quote leaves the record boundary uncertain. A quote in the middle of an unquoted field is also ambiguous. TableMender stops instead of inventing an interpretation. It reports the logical record associated with the error; that number can differ from the physical line number when earlier fields contain line breaks.

It also rejects unexpected text after a closing quote. Check whether the delimiter is wrong before editing the content. Some nonstandard exporters add spaces around quoted fields; this first version does not silently normalize that dialect.

Round trips need explicit choices

Changing a separator requires re-serializing parsed fields. The repair tool quotes fields when needed, doubles embedded quotes and uses CRLF between records. These changes can alter file bytes while keeping parsed field content intact. Formula protection is a separate option that intentionally changes selected values by prefixing an apostrophe.

Keep the scope clear

The tool supports common quoted-field CSV plus explicit semicolon, tab and pipe separators. It does not import an existing XLSX file or a proprietary binary export. Preserve your original and check the new file in its receiving application.

Edge cases and boundary cases

An unmatched opening quote is an error worth stopping on. Deleting the quote to “make the file open” can glue two records together or shift every later field. Fix the exporter or escape the field correctly instead of stripping structure.

Spaces between a closing quote and the next delimiter are a nonstandard dialect. This version does not silently normalize that spacing. If preview fails after a closing quote, check whether the delimiter itself is wrong before editing quotes—see Why your CSV opens in one column.

A quoted field may contain the active delimiter, doubled quotes and line breaks together. Physical line numbers then diverge from logical record numbers; use both locations when reading an error. Removing “blank lines” in a text editor can cut such a field in half—parse with CSV check & repair first.

Formula protection on CSV export may prefix an apostrophe to formula-like values. That is an intentional content change, separate from quoting. Turn it on only when the receiving spreadsheet would otherwise execute the field.

If Excel Save As rewrote multiline notes into a single line or doubled quotes unexpectedly, compare with the vendor file before further edits—see Excel Save As CSV pitfalls. Structural repair cannot restore note text that the grid already flattened away; re-export when the characters differ.

Worked errors this parser actually reports

Load quoted-records.csv or the “Quotes, commas and line breaks” sample pack entry in CSV check & repair. With Comma and a header, Preview should show 3 data records and 2 columns. These are the stops you get when the quotes are wrong, using the same wording as the tool:

The error banner now includes a What to do sentence with that same advice. Source locations under the preview show nearby physical lines so you can inspect a quoted line break without splitting it.

Step-by-step troubleshooting

  1. Preview count is wrong (too many records). A quoted line break was treated as a record break, usually because a quote is missing. Do not delete “blank lines” in a text editor until you have parsed the file.
  2. Preview count is wrong (too many columns). A comma inside an unquoted note became a separator. Quote the field.
  3. Download is blocked for uneven widths. One record has a different field count. The tool does not pad. Fix the exporter or the unmatched quote.
  4. You need a different delimiter on the way out. Parse first, then choose the output delimiter. Re-serialization quotes fields that need it and uses CRLF.

FAQ grounded in the repair tool

Why not guess a repair for unmatched quotes? Two plausible parses would silently shift later fields. A named error is safer than a wrong table.

Does formula protection change quoting? No. Protection prefixes an apostrophe on formula-like values during CSV export. Quoting is separate and still applied when the field contains the delimiter, quotes or line breaks.

Can I download a repaired CSV if quoting is valid? Yes. The file is named with a -repaired suffix so it does not replace the original. Keep both until you compare record counts and a multiline note.

Before and after: splitting lines versus parsing records

The teaching file is quoted-records.csv, also in the tool sample pack as “Quotes, commas and line breaks”. Load it in CSV check & repair with Comma and a header.

quoted-records.csv if you split naively, and if you parse it
ApproachWhat you get
Split every physical line, then every commaThe first note becomes two columns (Notebook and blue"). The last note becomes two records. The doubled quotes in the second note become noise
CSV check & repair, Comma, header on3 data records and 2 columns. Notes are Notebook, blue, He said "ready", and First line plus a line break plus Second line
Export Comma UTF-8 and re-importThe same parsed values. CRLF bytes may differ from another exporter. The -repaired file does not replace the sample

There are five physical lines and four logical records (header plus three). A quoted line break is one field. After the columns are trustworthy, identifier-style ids in the same file still need Text in CSV to Excel. A one-column open is a delimiter problem, not a quoting problem — see Why your CSV opens in one column.

Honest limits

The parser will not guess a fix for an unmatched quote. Two plausible parses would shift every later field, so it stops and names the record, physical line and field. It does not import an existing workbook, and it does not restore a note that Excel Save As already flattened. Spaces between a closing quote and the next delimiter are a nonstandard dialect this version does not silently normalize. Formula protection is a separate CSV option that prefixes an apostrophe; it is not a quoting repair. Keep the original until the re-imported multiline note matches.

Parse first. Delete a quote only when you know it is not the structure that holds a comma or a line break inside the field.

Sources:

Examples are original teaching data. Tool-specific behavior describes this version of TableMender; software interfaces can vary by version.

← All guides