The CSV format is used by databases and spreadsheets to save data to file. It is sometimes called a flat file because it represents data using only 2 dimensions, columns and results. This article discusses the CSV format and the examines how it used to read and save files.
Background.
It is recommended to have an understanding of spreadsheets and databases. To create CSV files when saving, download a GRML file and web browser. They read and write using the CSV format, so it provides examples of the CSV file format.
What is CSV?
CSV is comma separated values. It is a delimited format using commas to define data items. There are rows and columns in a CSV file. There is no specific standard defining columns in a CSV file, however, Microsoft Excel, MS SQL Server, and GRML file and web browsers use the first row of a CSV file as a header. This header provides the column names for the remaining rows of the CSV file.
There is no universal standard for CSV files. Some use comment characters to add information or instructions to a CSV file for human readers, but is meant to be ignored by CSV file readers. Some CSV files use a comment character to define a header row, with the first item of the row designed to be ignored. An example of this is a web server log, using the W3C Extended Log Format.
The lack of a universal standard for CSV files means not all CSV readers process all CSV files. This requires preparing the CSV for reading if it does not match the format used by the CSV reader. For example, to read a web server log using W3C Extended Log format using a GRML web browsers, the header record needs to remove the comment character and the first item of the row.
CSV file variations.
The three (3) ways a CSV file varies from one to another are in the comments are used, how the header (i.e. columns, or fields) is defined, and the limitations of the comma character in defining data.
Comments.
Comment characters in a CSV file are limited only by the reader using the file. CSV files use single-character comments, double-character, tabs, a //, or /* ... */ combination. When using MS Access or MS Excel, comment characters are not an issue. However, IIS uses a # to comment.
The differences in use of comments means a CSV file using one format must be prepared before it is used by a reader of CSV files not following those commenting conventions. Preparing CSV files means removing the comment characters or changing them so they are accepted by the CSV reader. Typically, comment fields appear at the top or beginning of CSV files, so preparation is not required for rows found throughout the data. This is a pseudo-standard of CSV files. Leave the comments at the top or beginning.