Comma-separated values
Infobox file format
name = Comma separated list
Comma-separated values
icon =
caption =
extension = .csv or .txt
mime = text/csv
text/comma-separated-values (deprecated)fact|By whom? YOU!??? |date=August 2008
type code =
uniform type =
magic =
owner =
released =
latest release version =
latest release date =
genre = multiplatform, serial data streams
container for =
contained by =
extended from =
extended to =
standard = RFC 4180
url =
The comma separated list (CSL) is a
Some early software applications such as
Comma-separated value lists are very old technology and predate personal computers by more than a decade; the IBM Fortran (level G) compiler under OS/360 supported these in 1967, and they were not a new idea at the time. Comma-separated value lists were often easier to type into punched cards than fixed-column-aligned data, and were less prone to producing competely bogus results if a value was punched one-column-off from its intended location (an easy mistake to make). The arguments against them were harder to justify (the main one being that they were "inefficient" to parse) when computers became so powerful they could execute hundreds of thousands of instructions per second.
Technical background
A
CSV is one implementation of a delimited text file, which uses a comma to separate values (where many implementations of CSV import/export tools allow an alternate separator to be used). However CSV differs from other delimiter separated file formats in using a " (
In
pecification
Comma separated lists date from before the earliest personal computers, but were widely used in the earliest pre-
While no formal specification for CSV exists, RFC 4180 from October 2005 describes a common format and establishes "text/csv" as the
Since csv files existed well before 2005 the RFC is only one special view on csv files.
Many informal documents exist that describe the CSV format. [http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm How To: The Comma Separated Value (CSV) File Format] provides an overview of the CSV format in the most widely used applications and explains how it can best be used and supported.
The basic rules from a lot of these specifications are as follows:
CSV is a
* Each record is one line terminated by a line feed (ASCII/LF=0x0A) or a carriage return and line feed pair (ASCII/CRLF=0x0D 0x0A), however, line-breaks can be embedded.
* Fields are separated by commas. 1997,Ford,E350
* In some CSV implementations, leading and trailing spaces or tabs, adjacent to commas, are trimmed. "This practice is contentious and in fact is specifically prohibited by RFC 4180, which states, "Spaces are considered part of a field and should not be ignored." 1997, Ford , E350 same as 1997,Ford,E350
* Fields with embedded commas must be delimited with double-quote characters. 1997,Ford,E350,"Super, luxurious truck"
* Fields with embedded double-quote characters must be delimited with double-quote characters, and the embedded double-quote characters must be represented by a pair of double-quote characters. 1997,Ford,E350,"Super ""luxurious"" truck"
* Fields with embedded line breaks must be delimited by double-quote characters. 1997,Ford,E350,"Go get one now they are going fast"
* Fields with leading or trailing spaces must be delimited by double-quote characters. "(See comment about leading and trailing spaces above.)" 1997,Ford,E350," Super luxurious truck "
* Fields may always be delimited by double-quote characters, whether necessary or not. "1997","Ford","E350"
* The first record in a csv file may contain column names in each of the fields. Year,Make,Model 1997,Ford,E350 2000,Mercury,Cougar
Example
The above table of data may be represented in CSV format as follows:
1997,Ford,E350,"ac, abs, moon",3000.00 1999,Chevy,"Venture ""Extended Edition""","",4900.00 1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00
This CSV example illustrates that:
* fields that contain commas, double-quotes, or line-breaks must be quoted,
* a quote within a field must be escaped with an additional quote immediately preceding the literal quote,
* space before and after delimiter commas may be trimmed, and
* a line break within an element must be preserved.
Application support
The CSV file format is very simple and supported by almost all
ee also
*
*
References
External links
*RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files
* [http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm How To: The Comma Separated Value (CSV) File Format]
* [http://supercsv.sourceforge.net/csvSpecification.html An EBNF definition of the CSV format with explanation]