{{Short description |Text format for tabular data using a tab between fields}} {{Infobox file format | name = Tab-separated values | icon = TsvDelimited001.svg | icon_size = 128px | logo = | screenshot = | caption = | _noextcode = on | extension = {{code|.tsv}}, {{code|.tab}}<ref name=Edinburgh>{{Cite web|url=https://www.ed.ac.uk/information-services/research-support/research-data-service/after/data-repository/choosing-file-formats|title=Choose the best file formats|publisher=University of Edinburgh|author=U of Edin. Research Data Support Team|at=§ Formats we recommend|access-date=2023-05-23}}</ref> | mime = text/tab-separated-values | type code = | uniform type = public.tab-separated-values-text<ref name="Apple UTI"/> | conforms to = public.delimited-values-text<ref name="Apple UTI"/> | magic = | owner = University of Minnesota Internet Gopher Team<br/><hr/>Internet Assigned Numbers Authority | type = Delimiter-separated values format | released = {{circa|{{start date and age|1993|06}}}} | latest release version = | latest release date = | genre = multiplatform, serial data streams | container for = database information organized as field separated lists | contained by = | extended from = | extended to = | standard = IANA MIME type | url = }}

'''Tab-separated values''' ('''TSV''') is a plain text data format for storing tabular data where the values of a record are separated by a tab character and each record is a line (i.e. newline separated).<ref>{{Cite web |title=How To Use Tab Separated Value (TSV) files |url=https://www.imf.org/external/help/tsv.htm |access-date=2023-02-01 |publisher=International Monetary Fund}}</ref> The TSV format is a form of delimiter-separated values (DSV) and is similar to the commonly-used comma-separated values (CSV) format.

TSV is a relatively simple format and is widely supported for data exchange by software that generally deals with tabular data. For example, a TSV file might be used to transfer information from a database to a spreadsheet.

== Example == The following are records of the Iris flower data set in TSV format. Since a tab is not a printable character (is invisible), an arrow (→) is used for demonstration here to denote a tab character.

{{not a typo|<pre> Sepal length→Sepal width→Petal length→Petal width→Species 5.1→3.5→1.4→0.2→I. setosa 4.9→3.0→1.4→0.2→I. setosa 4.7→3.2→1.3→0.2→I. setosa 4.6→3.1→1.5→0.2→I. setosa 5.0→3.6→1.4→0.2→I. setosa </pre>}}

The following is the same data rendered as a table.

{| class="wikitable" ! Sepal length ! Sepal width ! Petal length ! Petal width ! Species |- | 5.1 | 3.5 | 1.4 | 0.2 | I. setosa |- | 4.9 | 3.0 | 1.4 | 0.2 | I. setosa |- | 4.7 | 3.2 | 1.3 | 0.2 | I. setosa |- | 4.6 | 3.1 | 1.5 | 0.2 | I. setosa |- | 5.0 | 3.6 | 1.4 | 0.2 | I. setosa |}

If a text editor that supports Dynamic tab stops (aka. "elastic tabstops") is used to view the contents of a TSV file, the layout will look like the table rendering just without cell borders and header row formatting (though the latter can be achieved using Unicode characters).

== Known problems in comparison to CSV ==

# Unlike for CSV, there is no widely agreed-upon specification for TSV which can lead to inconsistent behaviors when dealing with backslashes or quotation marks or the disallowed tabs and line breaks. For TSV there is only a mime-type assignment. Escaping rules for line breaks and tabs are inconsistent among implementations. Some use backslash (\) notation from C, some the quoting rules from CSV, some simply can not store tabs and line breaks. # If backslash escaping is used backslashes also need to be escaped and line breaks in fields could become "\r\n" on Windows which may add another layer of line break handling # Non-technical users, who are editing TSV with a text editor, sometimes mix up tabs and spaces, corrupting the data. Empty fields may also be difficult to count in editors where tabs are merely shown as whitespace. # Despite lower complexity, fewer applications implement it. # The file size increase of quoting both commas and quotes in CSV is usually insignificant on modern systems. # Terminal emulators often render tabs as multiple spaces which prevents copying a tab correctly, thus preventing copying TSV formatted data directly from a selection on the terminal without combining all fields into one.

==Delimiter collision== As a form of delimiter collision, if a field (record value) contained a tab character, the data format would become meaningless since tabs were no longer ''only'' used between fields. To prevent this situation, the IANA media type standard for TSV simply disallows a tab within a field. Similarly, a value cannot contain a line terminator.{{Sfn|Lindner|1993}} To represent a value with an embedded tab or line terminator character, a commonly-used mechanism is to replace the character with the corresponding escape sequence as shown in the following table.<ref>{{cite web |last=Dusek |first=Jason |date=2014-05-06 |title=Linear TSV: simple, line-oriented, tabular data |url=http://dataprotocols.org/linear-tsv/ |website=Data Protocols - Open Knowledge Foundation |edition=v1.0β |access-date=6 May 2020 |archive-date=18 March 2023 |archive-url=https://web.archive.org/web/20230318091658/https://dataprotocols.org/linear-tsv/ |url-status=dead }}</ref><ref>{{cite web |last=Dolan |first=Stephen |date=2018-11-01 |title=<nowiki/>{{mono|jq}} Manual |url=https://stedolan.github.io/jq/manual/ |access-date=2023-05-23 |website=<nowiki/>{{mono|jq}}}}</ref> {| class="wikitable" |+ !sequence !represents |- |<code>\t</code> |tab |- |<code>\n</code> |line feed |- |<code>\r</code> |carriage return |- |<code>\\</code> |backslash |}

Another commonly-used convention, borrowed from CSV ({{IETF RFC|4180}}), is to enclose a value that contains a tab or line terminator character in quotes.<ref>{{Cite book |last=Miller |first=Rob |url=https://books.google.com/books?id=dg9QDwAAQBAJ&pg=PT94 |title=Text Processing with Ruby: Extract Value from the Data That Surrounds You |date=2015-09-22 |publisher=Pragmatic Bookshelf |isbn=978-1-68050-492-7 |pages=94 |language=en}}</ref><ref>{{Cite book |last1=Giuseppini |first1=Gabriele |url=https://books.google.com/books?id=vnIXo-yUT2gC |title=Microsoft Log Parser Toolkit: A Complete Toolkit for Microsoft's Undocumented Log Analysis Tool |last2=Burnett |first2=Mark |date=2005-02-10 |publisher=Elsevier |isbn=978-0-08-048939-1 |pages=311 |language=en}}</ref> Among others it's used by LibreOffice Calc where the backslash (\) notation is not implemented and TSV is simply treated as a variant of CSV with tab delimiters instead of comma.

==Line terminator== As for any text file, the character(s) used for line terminator varies. On a Microsoft-based system, normally it's a carriage return (CR) and line feed (LF) sequence. On a Unix-based system, it's just LF. The de-facto specification<ref>{{cite web |url=https://www.iana.org/assignments/media-types/text/tab-separated-values|title=IANA: text/tab-separated-values}}</ref> uses the term "EOL" which is an ambiguous term like line terminator and newline. Software often is designed to either handle the line terminator for the platform on which it runs or to handle either terminator.

<!--== See also ==-->

== References ==

<references>

<ref name="Apple UTI">{{cite web |url=https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3551577-tabseparatedtext |title=tabSeparatedText |work=Apple Developer Documentation: Uniform Type Identifiers |publisher=Apple Inc|ref={{harvid|Apple UTI}}|access-date=2023-05-23}}</ref>

</references>

=== Sources ===

* {{cite web|url=https://www.loc.gov/preservation/digital/formats/fdd/fdd000533.shtml|title=TSV — Tab-Separated Values|publisher=Library of Congress|id=fdd000533|edition=11 February 2021|access-date=2023-05-23|ref={{harvid|Library of Congress}}}} * {{cite web|last=Lindner |first=Paul |date=June 1993 |title=<nowiki/>{{mono|text/tab-separated-values}}|trans-title=Definition of tab-separated-values (tsv) |url=https://www.iana.org/assignments/media-types/text/tab-separated-values |access-date=2023-05-23 |work=Assigned Media Types Registry|others=IANA |publisher=University of Minnesota Internet Gopher Team |publication-place=Minnesota}} * {{cite web|url=https://www.imf.org/external/help/tsv.htm|title=How To Use Tab Separated Value (TSV) Files|archive-url=https://web.archive.org/web/20070112194522/http://www.imf.org/external/help/tsv.htm|url-status=live|archive-date=12 January 2007|access-date=5 March 2017}}

== Further reading ==

* {{Cite web|url=https://jkorpela.fi/TSV.html|title=Tab Separated Values (TSV): a format for tabular data exchange|last=Jukka|first=Korpela|date=2000-09-01|edition=12 February 2005|access-date=2023-05-23}} * {{Cite book|last=Welinder|first=Morten|date=2012-12-19|section-url=https://help.gnome.org/users/gnumeric/stable/gnumeric.html#file-format-tab|section=§14.2.3 — Text File Formats|title=The Gnumeric Manual|edition=v1.12|access-date=2023-05-23|archive-date=30 November 2020|archive-url=https://web.archive.org/web/20201130235637/https://help.gnome.org/users/gnumeric/stable/gnumeric.html#file-format-tab|url-status=dead}}

{{use dmy dates|date=May 2023}} Category:Spreadsheet file formats Category:Delimiter-separated formats Category:Computer file formats