TSV to CSV Converter

Turn a TSV into a CSV, a CSV into a TSV, or a semicolon file from a German copy of Excel into a comma file your import script accepts. The tool parses every field before writing it out, so a comma inside a quoted name stays in the name instead of starting a new column, which a find and replace on tabs cannot guarantee.

Input
Output

1 TSV to CSV Converter example

TSV input

1
2
3
4
id	name	city	note
1	Lovelace, Ada	London	wrote the "first" program
2	Hopper, Grace	New York	found an actual bug
3	Turing, Alan	Wilmslow	

CSV output

1
2
3
4
id,name,city,note
1,"Lovelace, Ada",London,"wrote the ""first"" program"
2,"Hopper, Grace",New York,found an actual bug
3,"Turing, Alan",Wilmslow,

The names contain commas, so the tool quotes them. The note with quotes in it is quoted too, and its inner quotes are doubled. Every other field is left unquoted.

2 When a field gets quoted

It contains the delimiter

A comma triggers quoting in CSV, and a tab triggers it in TSV. The rule depends on the target, so a value can be unquoted in the TSV and quoted in the CSV.

It contains a double quote

The field is wrapped in quotes and each inner quote is doubled, so say "hi" becomes "say ""hi""". This is the RFC 4180 rule, and Excel follows it.

It contains a line break

Quoted line breaks stay inside the field. The line numbers on the left count physical lines instead of records, so they can run ahead of the row count.

Always

Pick Always in the Quotes menu when an importer requires every field to be quoted. Empty fields then come out as "".

3 TSV differs from CSV with tabs

The IANA registration for text/tab-separated-values forbids tabs inside fields and has no quoting at all. However, most TSV files from Excel, Google Sheets and database exports quote the CSV way anyway, so this tool reads quotes when they are there. If your TSV has a " at the start of a value that is meant as a literal character, the parser treats it as an opening quote and the columns shift. The status line warns you when a quote is never closed.

Set From by hand when the stats show one column where you expected several. Auto-detect looks at the first 20 lines and picks whichever of comma, tab, semicolon or pipe appears the same number of times on each line, so it can guess wrong on a one-column file or a single-line file. The output keeps the input's line endings (CRLF or LF) and drops a leading BOM.

How to use the TSV to CSV Converter tool

  1. Paste TSV or CSV into the Input pane, or click Upload to load a .tsv, .csv or .txt file. Dummy Data loads a small TSV with awkward values.
  2. Leave From on Auto-detect or pick the input delimiter. Choose Custom to type any other separator (\t works for tab).
  3. Pick the target in To: Comma for CSV, Tab for TSV, or Semicolon, Pipe or Custom. Swap reverses the direction and moves the output back into the input.
  4. Set Quotes to Only when needed (RFC 4180 minimal quoting) or Always.
  5. Click Copy, or Download to save the result. The file is named .tsv when the target is Tab and .csv otherwise.

How to convert TSV to CSV in JavaScript, PHP and Python

JavaScript

function parse(text, d) {
  const rows = [[]];
  let f = "", q = false;
  for (let i = 0; i < text.length; i++) {
    const c = text[i];
    if (q) {
      if (c === '"' && text[i + 1] === '"') { f += '"'; i++; }
      else if (c === '"') q = false;
      else f += c;
    } else if (c === '"' && f === "") q = true;
    else if (c === d) { rows.at(-1).push(f); f = ""; }
    else if (c === "\n" || c === "\r") {
      if (c === "\r" && text[i + 1] === "\n") i++;
      rows.at(-1).push(f); f = ""; rows.push([]);
    } else f += c;
  }
  rows.at(-1).push(f);
  return rows.filter((r) => r.length > 1 || r[0] !== "");
}

const quote = (v, d) =>
  /["\r\n]/.test(v) || v.includes(d) ? '"' + v.replace(/"/g, '""') + '"' : v;

const tsvToCsv = (tsv, to = ",") =>
  parse(tsv, "\t").map((r) => r.map((v) => quote(v, to)).join(to)).join("\n");

console.log(tsvToCsv('id\tname\tnote\n1\tLovelace, Ada\twrote the "first" program\n'));

A quote at the start of a field opens a quoted field, while a quote in the middle of a value is kept as a literal character. Most TSV exports behave the same way.

PHP

<?php
$in  = fopen('data.tsv', 'r');
$out = fopen('data.csv', 'w');

while (($row = fgetcsv($in, null, "\t", '"', '')) !== false) {
    if ($row === [null]) continue;                  // blank line
    fputcsv($out, $row, ',', '"', '', "\n");
}
fclose($in);
fclose($out);

Passing an empty escape character (PHP 7.4+) makes fgetcsv and fputcsv follow RFC 4180 instead of treating backslash as special. The eol argument needs PHP 8.1.

Python

import csv, io

tsv = 'id\tname\tnote\n1\tLovelace, Ada\twrote the "first" program\n'

rows = csv.reader(io.StringIO(tsv), delimiter="\t")
out = io.StringIO()
csv.writer(out, delimiter=",", lineterminator="\n").writerows(rows)
print(out.getvalue(), end="")

# Files: open(..., newline="", encoding="utf-8") on both sides,
# and quoting=csv.QUOTE_ALL on the writer to quote every field.

The csv module handles quoting on both sides. Swap the delimiter arguments to go from CSV to TSV.

Common errors and how to fix them

Everything ends up in one column
The From delimiter is wrong, or auto-detect guessed wrong on a file with only one line. Set From by hand and check the rows x cols count in the output header.
Warning: a quoted field is never closed
A value starts with a double quote that is never closed, so the parser reads the rest of the file as one field. This happens most in TSV files that do not use quoting at all. Fix or remove that quote in the input.
Excel shows everything in column A after opening the CSV
Excel in many European locales expects semicolons. Convert To Semicolon, or import through Data > From Text/CSV and choose the delimiter there.
Accented characters look like é in Excel
The file is UTF-8 but Excel opened it as a legacy code page. Import via Data > From Text/CSV and choose UTF-8, or add a BOM when writing the file in code.

Good to know

RFC 4180 defines CSV quoting: fields containing the delimiter, a double quote or a line break are enclosed in double quotes, and inner quotes are doubled. The IANA registration for text/tab-separated-values is stricter and bans tabs inside fields. However, most TSV exports follow the CSV quoting rules, so this tool reads and writes those.

Specifications and references

This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.

Frequently Asked Questions

How do I convert a TSV file to CSV?

Paste the TSV or click Upload, leave From on Auto-detect and To on Comma. Copy the result or click Download .csv to save it.

How do I change the delimiter of a CSV file from semicolon to comma?

Set From to Semicolon (or Auto-detect) and To to Comma. The file is parsed and rewritten, so quoted values that contain commas get quoted correctly in the new file.

Can I convert CSV back to TSV?

Yes. Pick Tab in the To menu, or click Swap after a conversion to reverse the direction and feed the output back in. The download becomes a .tsv file.

Why are some fields wrapped in double quotes in the output?

A field is quoted when it contains the target delimiter, a double quote or a line break, as RFC 4180 requires. Choose Always in the Quotes menu if your importer wants every field quoted.

Is my file uploaded to a server?

No. Parsing and conversion run in JavaScript on this page, and Upload reads the file from your disk with FileReader without sending it anywhere.

After the delimiter is sorted

Tidy the rows with the CSV Cleaner, check the result in CSV to Table, or turn it into JSON or SQL INSERT statements.

More Data Converters

Browse all data converters

Copied to clipboard!