lessless
How are you dealing with CSV files that uses CR line breaks?
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there is a standing problem of reading them since File.* doesn’t support \r as a new line anyway.
Details:
https://github.com/elixir-lang/elixir/issues/6169
https://github.com/beatrichartz/csv/issues/55
Right now I see two possible solutions:
- read N chars, detect if
\rdoesn’t have\nafter it and consider that file uses CR as a line breaks, and then:
- Create and use NIF (still have to find a good C/C++ library)
- Replace
\rwith\r\n
Is there any better way? What are you folks doing in this situation?
Most Liked
jeremyjh
nimble_csv has :newlines / :line_separator options to handle this.
NobbZ
Everything that is able to distinguish between at least 5 basic types: Integers, Floats, Strings, Composites and an ordered kollection of items (List/Array).
Also it needs to support a Schema.
Therefore, whenever a client yells at me that he can provide a JSON or CSV dump of his database, then I ask for an SQL export instead.
If he wants to provide a CSV export of some OOo, LO or Excel spreadsheet, I ask for a copy of the spreadsheet.
If he insists on giving only CSV or JSON my boss doubles the price per hour…
We’ve been through many hoops that could have been avoided if we had access to raw data right away… So we came up with the solution mentioned above, after adjusting the payrate, most clients are able to provide raw data all of a sudden and they do not care for all the corporation policies they mentioned in the discussion earlier…
michalmuskala
Why not use a proper CSV library?
OvermindDL1
Just what I was about to say. I use nimble_csv myself and it has that ability, plus it was made by our own Jose Valim . ![]()
sztosz
I have the same problem, but I written thin csv to JSON converter, it’s not generic though. I simply scan documents from beginning and check what line ending I encounter first and what delimiter there was, comma or semicolon. Then pass it to proper csv reading library with proper line ending and delimiter.
Not the fastest approach, far from perfect, but so far in production had only one not parsed/erroring file and it was really XLS with csv file extension.
PS. That rust program is run through cli piping stdout back to an application.







