Skip to main content
2 of 5
added 4 characters in body; edited tags
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Importing CSV with multiline text fields

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