What Is TSV?
TSV stands for Tab-Separated Values, a plain-text tabular data format where fields on each row are separated by horizontal tab characters (\t, ASCII code 9) rather than commas. Like CSV, each row is terminated by a newline, and an optional first row may serve as a header with column names.
TSV is not standardised by any RFC or formal specification. It is defined purely by convention: tab-delimited, one record per line. Despite the lack of a formal standard, TSV is widely used in bioinformatics, scientific computing, linguistics (corpus data), and anywhere data fields may naturally contain commas — such as addresses, names with titles, or currency-formatted numbers.
Why Tab as Delimiter?
The tab character as a field separator has a practical advantage over comma: tab characters almost never appear in ordinary text data. Commas appear constantly in names (Smith, John), addresses (123 Main St, Suite 4), numbers in European locales (1.234,56), and free-text fields. This means CSV requires a quoting/escaping mechanism for these common cases, while TSV often does not.
| Problem scenario | CSV | TSV |
|---|---|---|
Smith, John |
Must be "Smith, John" |
Can be Smith, John directly |
$1,234.56 |
Must be "$1,234.56" |
Can be $1,234.56 directly |
| Multi-line address | Must quote | Must quote (tabs are rare, newlines are not) |
| HTML content | Quote and escape " as "" |
Fewer escaping needs |
The main case where TSV still needs quoting is when fields contain literal tab or newline characters, which is rarer than comma-in-data.
TSV vs. CSV: Detailed Comparison
| Aspect | CSV | TSV |
|---|---|---|
| Delimiter | Comma (,) |
Tab (\t) |
| RFC specification | RFC 4180 (informal) | None |
| Quoting needed for | Commas, quotes, newlines in data | Tabs, newlines in data |
| Human readability | Good (compact) | Good (aligned in editors) |
| Double-click open in Excel | Yes, as CSV | Yes, as tab-delimited |
| Prevalence | Very high | High in scientific/technical |
| Common file extensions | .csv |
.tsv, .tab, .txt |
| Used in bioinformatics | Occasionally | Very commonly (FASTA metadata, VCF, BED) |
TSV in Bioinformatics
TSV is the dominant tabular format in bioinformatics and genomics. Many standard bioinformatics file formats are TSV variants:
BED format (Browser Extensible Data):
chr1 1000 5000 gene1 0 +
chr1 6000 9000 gene2 0 -
Tab-separated: chromosome, start, end, name, score, strand.
VCF (Variant Call Format): A complex format for genetic variants with a TSV data section after a header block. The header lines start with #.
GFF/GTF (General Feature Format): Annotation data where features of a genome are described in 9 tab-separated columns.
BLAST output (tabular format -outfmt 6): Standard 12-column TSV output from BLAST sequence alignment searches.
SAM format (Sequence Alignment Map): Tab-separated format for aligned sequencing reads.
The genomics community standardised on TSV partly because sequence data, gene names, and coordinates never contain tab characters, eliminating quoting complexity. The awk command-line tool, pervasive in bioinformatics workflows, treats tab as its default field separator.
File Extensions
TSV files use multiple extensions:
.tsv— explicit and unambiguous.tab— common in bioinformatics.txt— generic; tool must detect the delimiter.csv— confusingly, sometimes used for tab-delimited files
When the extension is .txt or ambiguous, detecting the delimiter requires peeking at the file contents. A simple heuristic: if there are more tabs than commas in the first line, it is probably TSV. Tools like csvkit and pandas read_csv with sep='\t' handle both.
Opening TSV in Excel
Excel does not automatically open .tsv files as tab-delimited. Options:
Method 1: Rename the file to .txt, then open with File → Open. The Text Import Wizard will launch and allow specifying the delimiter.
Method 2: Data → From Text/CSV (or Get Data → From Text/CSV in newer Excel). Select the file and specify Tab as the delimiter in the import wizard.
Method 3: Rename to .csv and open. Excel may detect tabs automatically, but this is unreliable and depends on the system's regional settings.
Method 4 (for power users): Use Power Query (Get & Transform Data) which provides full control over delimiter detection, encoding, and column types.
Working with TSV Programmatically
Python csv module:
import csv
# Reading TSV
with open('data.tsv', newline='', encoding='utf-8') as f:
reader = csv.reader(f, delimiter='\t')
for row in reader:
print(row)
# Writing TSV
with open('output.tsv', 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f, delimiter='\t')
writer.writerow(['name', 'gene_id', 'expression'])
writer.writerow(['BRCA1', 'ENSG00000012048', '12.4'])
pandas:
import pandas as pd
# Reading TSV
df = pd.read_csv('data.tsv', sep='\t', encoding='utf-8')
# Writing TSV
df.to_csv('output.tsv', sep='\t', index=False)
awk (bioinformatics standard):
# Print second and fourth columns from TSV
awk -F'\t' '{print $2, $4}' data.tsv
# Filter rows where expression > 10
awk -F'\t' '$3 > 10 {print}' data.tsv
TSV Quoting Rules
Since TSV has no formal specification, quoting conventions vary:
No quoting: Many TSV files contain no quoting at all, assuming fields never contain tabs or newlines. This is the simplest approach and works well for structured data (genomics, log files, datasets).
With quoting: When TSV is generated by tools that follow CSV-style quoting but with a tab delimiter, fields containing tabs or newlines are enclosed in double quotes, with "" as the escape for a literal ". Python's csv.reader(f, delimiter='\t') uses this convention.
Bare newlines in fields: Some bioinformatics TSV formats simply forbid newlines in fields, avoiding the issue entirely.
Converting TSV
TSV → CSV: Change the delimiter:
import csv
with open('input.tsv') as infile, open('output.csv', 'w') as outfile:
reader = csv.reader(infile, delimiter='\t')
writer = csv.writer(outfile)
for row in reader:
writer.writerow(row)
Or with a command line tool: csvformat -T input.tsv > output.csv (csvkit).
TSV → JSON: Similar to CSV → JSON; each row becomes an object:
import csv, json
with open('data.tsv') as f:
reader = csv.DictReader(f, delimiter='\t')
data = list(reader)
with open('output.json', 'w') as f:
json.dump(data, f, indent=2)
TSV → XLSX: Via pandas or openpyxl:
pd.read_csv('data.tsv', sep='\t').to_excel('output.xlsx', index=False)
TSV → SQL: csvkit's csvsql supports --tabs flag:
csvsql --tabs --db sqlite:///data.db --insert data.tsv
When to Choose TSV over CSV
Choose TSV when:
- Data fields commonly contain commas (addresses, names, formatted numbers)
- Working in bioinformatics or scientific computing where TSV is the community norm
- Processing with
awk,cut, or other Unix tools that default to tab - The data will never be opened directly in Excel without a proper import procedure
Choose CSV when:
- Maximum compatibility with non-technical recipients who will double-click the file
- Working in environments where Excel is the primary tool
- The format spec requires CSV (many web APIs, form exports, database dumps)
Summary
TSV is CSV's quieter sibling — less famous, less widely documented, but often more practical for structured data that contains commas. The tab delimiter's rarity in real data eliminates most of the quoting complexity that plagues CSV, making TSV simpler to generate and parse correctly. Its dominance in bioinformatics and scientific computing reflects this practical advantage. When in doubt, both formats are interconvertible in one line of code; choose whichever delimiter is less likely to appear in your actual data.
Related conversions
Frequent conversions across the catalogue: