Comma-separated values

The comma-separated values (CSV) file format is a tabular data format that has fields separated by the comma character and quoted by the double quote character. If a field's value contains a double quote character it is escaped with a pair of double quote characters.

The CSV file format does not require a specific character encoding, byte order or line terminator format.

It is often not required by software to have fields quoted unless they contain a comma character.

Contents

Formal specifications

While no formal specification for CSV exists, there are several informal documents describing the format (1 (http://www.catb.org/~esr/writings/taoup/html/ch05s02.html), 2 (http://www.ricebridge.com/products/csvman/reference.htm), 3 (http://www.edoceo.com/utilis/csv-file-format.php) and 4 (http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm)). The closest thing to a formal specification is this Internet Draft (http://www.ietf.org/internet-drafts/draft-shafranovich-mime-csv-05.txt).

MIME type

There are several informal MIME types used for CSV including "application/csv", "text/x-csv", etc. The formal MIME type for CSV is "text/csv" as specified by an IETF draft (http://www.shaftek.org/publications/drafts/mime-csv/draft-shafranovich-mime-csv-02.html) and registered by IANA.

Example

"Chicane", "Love on the Run", "Knight Rider", "This field contains a comma, but it doesn't matter as the field is quoted"
"Samuel Barber", "Adagio for Strings", "Classical", "This field contains a double quote character, "", but it doesn't matter as it is escaped"

Application support

The CSV file format is a very simple data file format that is supported by almost all spreadsheet software such as Excel (Careful: some local versions use semicolons instead of commas!) and Gnumeric. Any programming language that has input/output and string processing functionality will be able to read and write CSV files.

CSV is similar in ubiquity for tabular data as ASCII files are for text data.

Programming language tools

.Net

CsvReader (http://www.geocities.com/shriop/index.html) is a commercial delimited file parsing utility focusing on speed and ease of use and usable from all .Net languages.

C/C++

Michael B Allen's CSV module (http://www.ioplex.com/~miallen/libmba/dl/src/csv.c) is small, complete, and robust.

Perl

With Text::CSV_XS and Text::CSV_PP

CSV files can be easily manipulated with the CPAN module Text::CSV_XS (http://search.cpan.org/author/JWIED/Text-CSV_XS/CSV_XS.pm). or with the equivalent pure perl module Text::CSV_PP (http://search.cpan.org/author/MAKAMAKA/Text-CSV_PP/lib/Text/CSV_PP.pm).

With DBI

CSV files can be accessed via SQL statements through DBI using a driver such as DBD::CSV (http://search.cpan.org/~jzucker/DBD-CSV-0.2002/lib/DBD/CSV.pm) or DBD::AnyData (http://search.cpan.org/~jzucker/DBD-AnyData-0.06/AnyData.pm).

With regular expressions

CSV files can be manipulated using Perl's built in text processing capabilites. This is easy to do incorrectly. For instance, the following code will convert comma delimited data into colon delimited data.

    perl -ne 'print join q(:),(split /,/,$_)' < input.csv > output.csv

That code does not deal with quote marks, an integral part of the CSV format.

Java

Direct interface

CSVReader/Writer (http://mindprod.com/products.html#CSV) provides a simple Java interface to CSV file I/O and is free.

The Java CSV Library (http://sourceforge.net/projects/javacsv/) is an open-source (LGPL) currently in beta.

Stephen Ostermiller has released a library[1] (http://ostermiller.org/utils/ExcelCSV.html) under the GPL to read and write CSV for Excel.

This CSV class (http://www.ioplex.com/~miallen/CSV.txt) is small, complete, and has been widely used in production environments.

Ricebridge Java CSV Component (http://www.ricebridge.com/products/csvman.htm) is a commercial CSV interface for high-speed, high-volume data handling.

JDBC interface

CsvJdbc (http://sourceforge.net/projects/csvjdbc/) is a read-only JDBC driver released under the LGPL.

StelsCSV (http://www.csv-jdbc.com/) is a commercial JDBC driver for CSV file databases. It supports much of SQL'92.

FOSITEX by i-net software also includes a CSV JDBC driver [2] (http://www.inetsoftware.de/products/jdbc/fositex/).

On Microsoft Windows one can access a CSV file through SQL using ODBC. See Using CSV Files as Databases and Interacting with Them Using Java (http://www.devarticles.com/c/a/Java/Using-CSV-Files-as-Databases-and-Interacting-with-Them-Using-Java/).

Python

Python has a csv module (http://www.python.org/doc/current/lib/module-csv.html) in the standard library since version 2.3.

Utilities

The csvprint (http://www.ioplex.com/~miallen/libmba/dl/examples/csvprint.c) utility will reformat CSV input based on a format string. This can be useful for reordering fields or generating source code or tables as illustrated in the following example:

 $ csvprint data.csv "\t{ %0, %1, %2, \"%3\" },\n"
         { 0xC0000008, 0x00060001, NT_STATUS_INVALID_HANDLE, "The handle is invalid." },

de:CSV-Datei fr:Comma separated values ja:カンマ区切りテキスト pl:CSV

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools