Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore newlines in CSV value

Tags:

newline

csv

So I have a CSV that contains a filename and a file's contents. The file is full of newlines and all sorts of other characters. I need to have each row contain the filename in one column and the file contents in the next column, and then I need a new row, until the end of the file.

The data looks like this:

"filename.txt","hey there
buddy
how are you
doing"
"filename2.txt","and so on..."

According to http://creativyst.com/Doc/Articles/CSV/CSV01.htm#EmbedBRs, my CSV importer should read those line-breaky values as single values, not new rows. However, I have tried OO Calc, KSpread, Gnumeric, and even Microsoft Excel 2007 and none of them read it that way; they all consider each newline a new row.

Anyone know how to fix this? I've looked through other related questions but none of them seem to say.

If this doesn't work, I'll have to write the file directly with a Python Excel-writing module or something. Anyone know what to do here?

like image 851
jeffcook2150 Avatar asked Jan 29 '26 17:01

jeffcook2150


2 Answers

The file has to have a .csv extension. Doesn't seem to work otherwise. Bug in Excel as far as I'm concerned.

like image 96
Dylan Nicholson Avatar answered Feb 01 '26 09:02

Dylan Nicholson


The free LumenWorks CSV reader handles newlines in the data if you set an appropriate flag.

like image 24
Eric J. Avatar answered Feb 01 '26 09:02

Eric J.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!