LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2017, 09:11 PM   #1
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,953

Rep: Reputation: 270Reputation: 270Reputation: 270
Is there a spec for comma-separated-variable files?


OpenOffice's spreadsheet program treats spaces as separators; Microsoft's Excel doesn't. I'm used to space-including entries in a CSV being quoted; I suspect OpenOffice is too. I couldn't find a spec.
 
Old 12-22-2017, 09:20 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
RFC-4180

When I generate CSV data I always double-quote each column even though it is optional. That seems to work well for OpenOffice and Excel (at least those who use excel do not complain, at least about the column data).

I often see people use "CSV" to refer to space separated fields and tab separated fields, and the wording of your question suggests that this might also apply to your case. I am not aware of a spec for space or tab separated field data format, and comma separated values, CSV, literally means that a comma is used as the separator. Using a comma as the separator according to RFC-4180 works well as an interchange format across all spreadsheets in my experience.

Last edited by astrogeek; 12-22-2017 at 09:43 PM. Reason: Added comments
 
1 members found this post helpful.
Old 12-23-2017, 12:11 AM   #3
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,953

Original Poster
Rep: Reputation: 270Reputation: 270Reputation: 270
Quote:
Originally Posted by astrogeek View Post
Thanks. That has the information I want, including
Quote:
there is no formal specification
and the observation that Excel uses no double quotes.

Quote:
Originally Posted by astrogeek View Post
When I generate CSV data I always double-quote each column
Even numerics?

I downloaded a spreadsheet from Fidelity in CSV (their designation) format. I don't have Excel so used Open Office. Fidelity told me they thought the spreadsheet looked fine when I complained, so I went to the library to open it in Excel - thus I figured out the problem with spaces.

I use sc; I wrote a utility to convert CSV to SC and vice-versa. My first attempt relied on comma separators but that didn't work in Open Office, so I tested every field for alphas and quoted them, which doesn't work for all-digit strings. Quoting all strings would be a good standard - too bad CSV has no spec.

Note Excel can't include a comma in a field.
 
Old 12-23-2017, 12:35 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by RandomTroll View Post
Thanks. That has the information I want, including and the observation that Excel uses no double quotes.
You are welcome, glad it helped!

Quote:
Originally Posted by RandomTroll View Post
Even numerics?
Yes, even numerics. I regularly export from a MySQL database to CSV format for a few remote users, and have written a few functions based on RFC-4180 just for that purpose. That is why I have it fresh in mind that I double-quote everything. That said, I do recall in the dim past that we had to explore a few Excel options to keep it from mangling the imported data. For example, I recall that we had to set some import option to prevent removal of leading zeros from zip code fields, among a few other things, but we found solutions online easily enough.

I do not run any M$ systems so have no way to test with Excel locally. I have OO but honestly rarely use it, although I know that I have in past imported these same CSV files without problems.

(Note: I normally use sc myself when I need a spreadsheet, great little application! But I find I don't use spreadsheets much any more!)

Good luck!

Last edited by astrogeek; 12-23-2017 at 12:55 AM.
 
Old 12-23-2017, 11:57 AM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,725

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
My recollection is that Excel suffixes a space-delimited file with .prn; tab delimited files are .txt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Anything that can easily manipulate Comma Separated Value (.csv) files? grumpyskeptic Linux - Software 9 01-02-2017 11:13 AM
[SOLVED] Bash script to merge files together (given as a comma separated string) DomeKor Linux - Newbie 10 09-27-2011 11:29 PM
Reading comma separated variable into other variables in shell script suryaemlinux Programming 5 12-22-2010 07:38 PM
Getting all the files modified today & store the names in a variable as , separated ananthi_ku Linux - Newbie 3 04-27-2009 05:01 AM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 05:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration