5

I have a .txt file consisting of very long paragraphs, with a single newline character separating each paragraph. I would like to convert this to a .csv format so that the file effectively has one column holding all the paragrahs, i.e., the first cell in each "row" contains the entire paragraph. However, I cannot use Excel to do this by simply opening the file in Excel and saving it as .csv, because some of my paragraphs are larger than the 1015 character limit that MS Excel has on a single field.

2

Assuming the text is properly escaped (i.e. embedded commas and linefeeds are double-quoted) you can just rename the file to .csv. There is nothing otherwise special about a CSV file format. It is essentially a text file.

There's actually a spec for CSV (you can read here). Note the rules for enclosing fields with double quotes: "Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes," and "If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote."

For example:

"You want to convert text to CSV," she noted.
This line doesn't need quotes (but they don't hurt).

Becomes:

"""You want to convert text to CSV,"" she noted."
"This line doesn't need quotes (but they don't hurt)."
  • It's not escaped. I guess I could do a find+replace for all the relevant characters to add the double quotes, though. Thanks. – user216357 Apr 12 '13 at 1:08
  • 2
    To turn the current text into valid CSV, you can replace every double quote with a pair of double quotes, and then add a double quote to the beginning and end of each line. – Bradd Szonye Apr 12 '13 at 1:21
  • Yes. Notepad++ would be especially good for this. – Jamie Hanrahan Jun 9 '17 at 9:09

protected by Community Jun 9 '17 at 8:40

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.