Convert tab-delimited text and TSV to CSV

What changes, what can break, and when to keep plain TSV: a practical review of converting tab-delimited text files to CSV, with a quoting example.

Converting a tab-delimited text file to CSV looks like a simple swap of one separator for another. A correct conversion does more than that, because commas, quotation marks and line breaks inside your data have to be handled so that each value stays in its own column. This review explains what the conversion changes, where it can go wrong, and when you are better off keeping the original TSV.

Is converting TSV to CSV the right choice?

Convert when the place you are sending the data expects CSV, such as an import form, a database loader or a script that only reads comma-separated input. The main benefit is compatibility, since CSV is the more widely requested of the two formats. The main tradeoff is that commas are common in ordinary text such as names, addresses and descriptions. Many CSV values therefore need quoting, which makes the file harder to read and edit by hand than the TSV it came from.

Keep the plain tab-delimited text when the destination already accepts TSV, when people will read or edit the file in a text editor or terminal, or when your values often contain commas and rarely contain tabs. In those cases converting adds quoting and escaping without any practical gain.

What the conversion actually changes

Tab-to-CSV conversion changes the stored characters in the file. It is not a visual or font effect, and it is not a reversal or mirroring of text. Every value should come out containing the same characters it went in with. Only the characters that separate and protect those values change:

  • Field separators: each tab that separates two values becomes a comma.
  • Quoting: a value that contains a comma, a double quotation mark or a line break is wrapped in double quotation marks.
  • Escaping: a double quotation mark inside a quoted value is doubled, so "hi" becomes ""hi"".
  • Row separators: rows stay one per line. A converter may also standardize line endings.

The example below shows a three-column TSV input. The columns are separated by tab characters.

id	name	note
007	Smith, Jane	Said "hi"

A correct conversion of that input produces the following CSV. The name is quoted because it contains a comma. The note is quoted because it contains quotation marks, and those inner quotation marks are doubled. The leading zeros in 007 are still present in the text.

id,name,note
007,"Smith, Jane","Said ""hi"""

A plain find-and-replace of tabs with commas would turn the second row into 007,Smith, Jane,Said "hi". Programs reading that line would see four columns instead of three, so Smith and Jane would land in separate columns. Quoting is what separates a real conversion from a character swap.

Common ways a conversion can lose meaning

Issue | What happens | What to check
Unquoted commas | Values split into extra columns | Commas inside values are quoted in the output
Quotation marks in TSV | Some readers treat a leading quote as the start of a quoted field and may merge or drop characters | Quotation marks in the source survive as literal text
Tabs or line breaks inside values | Rows or columns shift | Row and column counts match before and after
Uneven rows | Some rows have more or fewer fields than the header | Missing or extra fields are reported, not silently padded or trimmed
Character encoding | Accented letters, non-Latin scripts or emoji appear garbled | Input and output use the same encoding, such as UTF-8
Type guessing on open | A spreadsheet may reformat values like leading-zero codes, long numbers or date-like strings | Open the CSV as text or import columns as text if exact values matter

Type guessing is not part of the conversion itself. The CSV file can contain 007 exactly while the program that opens it displays something else. How a given spreadsheet application treats such values depends on the application, its version and its settings. No tested results for specific applications were available for this review, so check your own destination with a sample row.

Converting with a short script

If you prefer not to paste data into a web page, a few lines of Python using the standard csv module handle quoting automatically. This version reads tabs as separators and treats quotation marks in the TSV as ordinary characters. The writer then quotes and escapes values as CSV requires.

import csv

with open("input.tsv", newline="", encoding="utf-8") as src, \
     open("output.csv", "w", newline="", encoding="utf-8") as dst:
    reader = csv.reader(src, delimiter="\t", quoting=csv.QUOTE_NONE)
    writer = csv.writer(dst)
    writer.writerows(reader)

Remove quoting=csv.QUOTE_NONE only if your TSV was itself written with quoted fields, for example to hold tabs or line breaks inside values. Choosing the wrong setting can merge or split fields, so compare a few rows of output against the source.

Using a TSV to CSV converter online

Browser-based converters are convenient for small, non-sensitive files. Their conversion quality varies, and no specific tool was tested for this review. Before relying on one, run it on a sample that contains a comma, a quotation mark and a leading zero, then confirm the output matches the quoting shown above. A tool's appearance or marketing language is not evidence of how it handles your data. Unless its documentation clearly states that processing stays in your browser, assume the text may be sent to a server, and do not paste personal, financial or confidential records.

Will the result stay readable and usable after sharing?

Copying and pasting: CSV is plain text, so copying it between text editors keeps the characters intact. Pasting CSV text into a spreadsheet cell or a chat message may not split it into columns, because some programs split pasted text on tabs rather than commas. If you only need to move data into a spreadsheet by pasting, the original tab-delimited text may work better than the CSV.

Reading order and assistive technology: the conversion keeps values in their original order, left to right and row by row. Text in right-to-left scripts inside a value keeps its stored characters. A raw CSV file, however, is not a table to a screen reader. It is read as a continuous line of text with commas and quotation marks, which is hard to follow. If the goal is for people to read the data, share it as a properly structured table in a document, web page or spreadsheet, with header cells marked as headers, or provide a plain-language summary. Keep the CSV for software.

Search and editing: searching a CSV for a value usually works, but values with doubled quotation marks will not match a search for the original text. Hand edits can easily break quoting, so for anything beyond small fixes, edit in a tool that understands CSV and export again.

Bottom line

Converting tab-delimited text to CSV is worthwhile when a destination requires CSV, provided the converter quotes and escapes values correctly. Verify it with a sample containing commas, quotation marks and leading zeros, and check row and column counts afterward. Keep the TSV when the destination accepts it or when people need to read and edit the raw file. Use a structured table, not raw CSV, when the audience is human readers, including people using assistive technology.