Skip to main content
4 of 5
edited body
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Importing CSV with multiline text fields

Bug introduced in 8 or earlier and fixed in 11.2.0


Here is a valid CSV:

a1,b1,c1,d1,"e1
e1
e1"
a2,b2,"c2
c2
c2",d2,e2

It has two rows and five columns, and contains two fields with embedded CRLF. (See the CSV standard). But Mathematica doesn't parse it as such.

Import["test.csv", "CSV"]

Result:

{{"a1,b1,c1,d1,\"e1"}, {"e1"}, {"e1\""}, {"a2,b2,\"c2"}, {"c2"}, {"c2\"", "d2", "e2"}}

The result is the same if I use

Import["test.csv","CSV","TextDelimiters"->"\""]

How can I get Mathematica to parse the CSV correctly?

jcai
  • 173
  • 1
  • 4