The basics
What is a TSV file?
A TSV file stores a table as text. Each line is a row, and a tab separates one field from the next. Databases export it, spreadsheets import it, and command-line tools such as cut, paste, sort and awk work with it directly; cut and paste even use the tab as their default separator.
You also make TSV every time you copy cells in a spreadsheet: the plain-text version on the clipboard is tab-separated, which is why pasting it into a text editor lines up in columns and pasting it back into a sheet splits into cells. Many scientific formats, such as BED, GFF and VCF in genomics, are tab-separated text with extra rules.
Three things a TSV file is not:
- Not a spreadsheet. No formatting, formulas, column widths or multiple sheets. Saving a workbook as tab-delimited text keeps only the active sheet's values.
- Not typed. Every field is text; numbers and dates are whatever the reader decides they are.
- Not CSV with tabs, quite. CSV has quoting rules for awkward values. The IANA definition of TSV has none: it simply forbids tabs inside fields.
Anatomy
What's inside a TSV file
A TSV file is lines of text with tabs between the fields. Tabs are invisible in most editors, so in this example each one is drawn as →. Here is a small product list, part by part.
sku→name→price→stock→note
000184→Mug→12.50→48→Stoneware, 350 ml
000185→T-shirt→24.95→→Sizes S to XL
000186→Notebook→4.00→300→
000187→Poster→9.99→35→Says "50 × 70 cm"
000188→Pen set→1.25→0→Pack of 3\nrefills sold separately- 1
sku→name→price→stock→noteThe header line
The IANA registration makes the first line special: it holds the field names. In practice some files have no header, and nothing in the file says which kind you have.
- 2
→The separator
One tab character between fields. Not spaces: an editor that turns tabs into spaces breaks the file, even though it looks the same on screen.
- 3
Stoneware, 350 mlCommas are just data
No quotes are needed around commas, semicolons or decimal commas. That's the main reason to choose TSV over CSV.
- 4
000184Everything is text
TSV has no types. Whether
000184keeps its zeros or becomes the number 184 depends on the program that opens the file. - 5
24.95→→SizesAn empty field
Two tabs in a row: the stock is empty, not zero. Strictly, the IANA grammar requires at least one character per field, but empty fields are everywhere in practice.
- 6
300→A trailing tab
The line ends with a tab, so the last field (the note) is empty. Editors and tools that trim trailing whitespace delete it, and the row loses a field.
- 7
Says "50 × 70 cm"Quotes are just data too
In TSV a double quote is an ordinary character. Readers that also handle CSV-style quoting (Excel, LibreOffice, Python's
excel-tabdialect) only treat it specially when a field starts with one. - 8
Pack of 3\nrefills sold separatelyAn escaped line break
The IANA format has no way to put a tab or line break inside a field. Databases write them as escapes like
\n, which only a reader that knows the convention turns back into a line break. - 9
(the end of each line)Line endings
The registration only says EOL. Files from Unix tools and databases usually use LF; files from Windows programs often use CRLF. A reader that splits on LF alone leaves a stray
\rat the end of the last field of CRLF files.
IANA
The rules: what the registration says
TSV's only formal definition is its IANA media type registration, written by the University of Minnesota's Internet Gopher Team. Its specification section opens with "Doesn't really need any, but here goes" and fits on one screen:
- 1Each record is one line. Each field value is text.
- 2Fields in a record are separated by a tab character.
- 3"Fields that contain tabs are not allowable in this encoding."
- 4The first line is special: it contains the name of each field, separated by tabs.
- 5Each record must have the same number of fields.
Its short grammar also says each field has at least one character, which would rule out empty fields, and it doesn't define EOL or say how to handle a line break inside a value. Real files have empty fields and need line breaks, so tools filled the gaps in different ways.
Serving TSV
Send TSV as Content-Type: text/tab-separated-values; charset=utf-8. Without the charset, browsers and clients guess the encoding, and accented letters can turn into mojibake.
Escaping
How tabs and line breaks get into TSV anyway
Because the format itself forbids them, every tool that needs a tab, line break or backslash inside a value invents a way to write it. Four conventions are common:
| Convention | Tab in a value | Line break | NULL | Used by |
|---|---|---|---|---|
| Backslash escapes | \t | \n (and \r) | \N | PostgreSQL COPY in its default text format, which writes a backslash as \\ |
| Backslash before the character | \ then a real tab | \ then a real line break | \N | MySQL SELECT … INTO OUTFILE; LOAD DATA also reads \t and \n |
| CSV-style quotes | The value in "…" | The value in "…" | Empty | Excel, LibreOffice Calc, Python's csv module with delimiter="\t" |
| Replace or drop | A space | A space | Empty | Many simple exporters, which lose information |
The conventions don't mix. Read a PostgreSQL export with a CSV-style reader and Line one\nLine two stays as literal backslash-n; read a quoted file with a backslash reader and the quotes stay in the data. Check how the file was made, and tell your reader: in Python, csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE) turns quote handling off, and you unescape backslashes yourself.
sample-database-export.tsv below is written the way PostgreSQL's COPY … TO … (FORMAT text, HEADER true) writes it, with \t, \n, \\ and \N, and a row that holds the text \N rather than a NULL.
Comparison
TSV vs CSV: which should you use?
| TSV | CSV | |
|---|---|---|
| Separator | Tab | Comma (semicolon in many European Excel locales) |
| Specification | IANA registration, a few lines | RFC 4180 (informational, 2005) |
| MIME type | text/tab-separated-values | text/csv |
| Commas in values | Fine as they are | Value must be quoted |
| Tabs in values | Not allowed; escaped by convention | Fine as they are |
| Line breaks in values | Not allowed; escaped by convention | Allowed inside quotes |
Decimal commas (12,50) | No clash | Clash, hence semicolon CSV |
| Readable in a text editor | Yes, columns often line up | Yes |
| Best for | Data full of commas, pasting into sheets, Unix tools, database dumps | Exchange with almost any program |
Choose TSV when the values are full of commas (addresses, descriptions, numbers with decimal commas), when people will paste the data into a spreadsheet, or when it goes through shell tools. Choose CSV when the other side expects CSV, or when values can contain tabs and line breaks and you don't control both ends.
Troubleshooting
Why does my TSV file come out wrong?
- Everything lands in one column. The file has spaces, not tabs, often because an editor set to "insert spaces" or a web page converted them. Turn on "show whitespace" in your editor to see which you have.
- The last column has a stray character or won't parse as a date. CRLF line endings read by a program that splits on LF only leave
\rat the end of each line. Open the file in a mode that handles both, or convert the line endings. - Some rows have one field fewer. Trailing tabs, which mark empty last fields, were trimmed by an editor or script.
- Rows merge or split strangely. A field starts with a double quote, and a quote-aware reader treated everything up to the next quote as one value, tabs and line breaks included. Turn quoting off when reading files that don't use it.
- Leading zeros, long numbers and dates change in a spreadsheet. The same automatic conversions as for CSV. Import the columns as text; see why Excel changes CSV values.
- Accents turn into é or question marks. The file is UTF-8 and was read as another encoding, or the program that wrote it used a legacy code page. Choose UTF-8 when importing.
How to
How to open, edit and convert a TSV file
- Excel: use Data, From Text/CSV and check that the delimiter is Tab, which also lets you set column types before loading. To save, choose Text (Tab delimited), which writes a
.txtfile of the active sheet only; rename it to.tsvif needed. On Windows that option doesn't write UTF-8, so characters outside your system's code page are lost; Unicode Text writes tab-separated UTF-16 instead. - Google Sheets: File, Import, Upload, with the separator type set to Detect automatically or Tab. Untick converting text to numbers, dates and formulas to keep values as written. File, Download, Tab Separated Values (.tsv) exports the current sheet.
- LibreOffice Calc: opening a
.tsvshows the Text Import dialog; tick Tab as the separator and set column types there. To save, choose Text CSV with Edit filter settings, and pick {Tab} as the field delimiter. For headless conversion, pass--infilter="CSV:9,34,76"(9 is the tab's character code, 76 is UTF-8); without it LibreOffice splits on commas. - Text editors show it as it is. Code editors can display tabs as arrows, and some have a column mode that aligns them.
- Command line:
cut -f2 file.tsvprints the second column,awk -F'\t'andsort -t$'\t'split on tabs, andcolumn -t -s$'\t' file.tsvaligns it for reading. - Code: Python's
csvmodule withdelimiter="\t"or pandasread_csv(path, sep="\t"); set the quoting option to match how the file was written.
Security
Is a TSV file safe? Spreadsheet formula injection
TSV is plain text and can't hold macros. It has the same weakness as CSV, though: a spreadsheet treats a cell that starts with =, +, - or @ as a formula. If an application exports user-supplied text to TSV and someone typed =HYPERLINK(…) into a form, the formula runs when a colleague opens the export.
- Escape on export. OWASP suggests prefixing risky values with an apostrophe, so spreadsheets show them as text. Its other suggestion for CSV, adding a tab inside a quoted value, doesn't fit TSV, where a tab is the separator.
- Mind the side effects. An escape changes the data for every program that reads the file later, and some legitimate values start with
-or+, such as negative numbers and phone numbers. - Import, don't open. For a file you don't trust, import it with every column set to text, or read it in a text editor.
The full list of dangerous first characters and escaping options is on the CSV page; it applies to TSV unchanged, apart from the tab trick.
Free downloads
Sample TSV files to download
Free sample TSV files for testing importers, parsers, uploads, encodings and size limits. All are UTF-8 without a byte order mark, and each one parses with Python's csv module (delimiter="\t") with the same number of fields on every row.
Loading…What's inside sample-products.tsv
TSV has no comments, so the test cases are in the data. Open the file in an editor that shows whitespace to see the tabs.
Row 1: the header
Eight field names, as the IANA registration expects. Every row after it has exactly eight fields.
The sku column
Codes with leading zeros, such as
000184. A spreadsheet that converts them to numbers shows184.Prices and dates
Decimal points (
12.50) and ISO 8601 dates (2026-10-01), which read the same in every locale.Commas and semicolons in descriptions
Stoneware, 350 ml, dishwasher safeandPack of 3; refills sold separatelyneed no quotes in TSV.A quote inside a value
Canvas bag with a "99" print. The quote isn't at the start of the field, so quote-aware and plain readers agree on it.Zero is not empty
The pen set has a stock of
0, a value, unlike the empty fields insample-empty-fields.tsv.Encoding and line endings
UTF-8 (
×,²), LF line endings and a final line break.sample-crlf.tsvholds the same data with CRLF.
All sample TSV files
Product list
sample-products.tsv · 706 bytes
Eight fictional products with a header row: codes with leading zeros, prices, stock, colours, descriptions full of commas and an ISO date. UTF-8, LF line endings.
- Testing a TSV importer or parser
- Teaching the format
Same data, CRLF line endings
sample-crlf.tsv · 715 bytes
The product list with Windows line endings (
\r\n): 9 bytes bigger, one per line.- Catching a stray `\r` in the last column
- Testing line-ending detection
Empty fields and trailing tabs
sample-empty-fields.tsv · 405 bytes
Empty fields in the middle, a row ending in a trailing tab, two empty fields in a row, a row of nothing but tabs after its ID, and a name with spaces around it. Each row's note says what it tests.
- Checking empty fields aren't dropped or merged
- Catching tools that trim trailing tabs
UTF-8 in 11 languages
sample-utf8.tsv · 628 bytes
Greetings and city names in Latin with diacritics, Greek, Cyrillic, Arabic, Hebrew, Devanagari, Thai, Chinese, Japanese and Korean, plus currency symbols and emoji. No byte order mark.
- Spotting encoding bugs in importers
- Checking right-to-left text in a table
Database export with escapes
sample-database-export.tsv · 384 bytes
Six user rows in PostgreSQL
COPYtext format with a header:\tand\ninside values, backslashes written as\\, NULL as\N, an empty string that isn't NULL, and the literal text\N.- Testing backslash unescaping
- Telling NULL from an empty string
1 MB TSV file
sample-1mb.tsv · 1 MB (1,048,576 bytes)
A header and 19,561 fictional orders, eight fields per row, with LF line endings. The last row's note pads the file to exactly 1,048,576 bytes (1 MiB).
- Upload and size-limit tests
- Import performance
Ways to test with them
- Line endings: read
sample-products.tsvandsample-crlf.tsvand compare theupdatedcolumn. If the CRLF version's dates don't parse, your reader kept the\r. - Empty fields: every row of
sample-empty-fields.tsvmust come out with five fields, including row 5, which is an ID followed by four tabs. - Escapes: after unescaping
sample-database-export.tsv, row 3's bio should contain two real tabs, row 2's website should be NULL, and row 4's should be an empty string. - Spreadsheet import: paste or import
sample-products.tsvinto Excel or Google Sheets and check whether000184keeps its zeros. - Size limits:
sample-1mb.tsvis exactly 1,048,576 bytes, so you can test an upload limit right at the boundary.
Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.
Put it online
Have a TSV file? Give it a link.
Drop a TSV file on 99helpers and it gets its own web address. Visitors see it as plain text in the browser, and scripts or spreadsheets can fetch it from the same link.
Questions
TSV files, frequently asked
What does TSV stand for?
Tab-Separated Values: the values in each row are separated by tab characters.
How do I open a TSV file?
In any text editor to see it as it is, or import it into Excel (Data, From Text/CSV), Google Sheets (File, Import) or LibreOffice Calc, choosing Tab as the separator.
What's the difference between TSV and CSV?
The separator, and with it the escaping. CSV uses commas and puts awkward values in quotes. TSV uses tabs, so commas need no quotes, but tabs and line breaks inside values have to be escaped by some convention.
Can a TSV value contain a tab or a line break?
Not in the format as registered with IANA. Tools work around it: PostgreSQL writes \t and \n, MySQL puts a backslash before the character, and spreadsheets use CSV-style quotes.
How do I convert TSV to CSV?
Open it in a spreadsheet and save as CSV, or use a CSV library: read with delimiter="\t" and write with commas, so values that contain commas get quoted. Replacing tabs with commas in a text editor breaks any value that contains a comma.
How do I save a spreadsheet as TSV?
Google Sheets: File, Download, Tab Separated Values. Excel: File, Save As, Text (Tab delimited), which saves the active sheet as .txt. LibreOffice: Save As Text CSV with Tab as the field delimiter.
Is .tab the same as .tsv?
Usually. .tab is another extension used for tab-separated text, but it's also used by unrelated formats, such as MapInfo's table files. Check the content.
Can a TSV file contain a virus?
It can't contain programs or macros. It can contain formulas that a spreadsheet runs when the file is opened, so import untrusted files as text.
Related formats
Other file types explained
Keep going
Related
Sources
- IANA media type registration: text/tab-separated-values
- PostgreSQL documentation: COPY (text format)
- MySQL 8.4 Reference Manual: LOAD DATA
- Python documentation: csv module
- Microsoft: Save a workbook to text format
- OWASP: CSV Injection
Last reviewed 27 October 2026.