How to Open a TSV File and Read It Correctly
Open TSV files in a spreadsheet, text editor, command line or Python, confirm the tab delimiter, and keep leading zeros, dates and encoding intact.
A TSV file (tab-separated values) is a plain-text table. Each line is a row, and a tab character separates the fields within that row. Opening one is easy. Reading it correctly takes two extra checks: the program has to split columns on tabs and not on commas or spaces, and it should not reformat values such as ZIP codes, IDs or dates. This guide covers both.
What opening a TSV file actually involves
A TSV file holds only text. It has no formatting, formulas or cell types. Any program that can display text can show it, but to get a table, the program must interpret the tab as a column separator. Detecting that separator is called dialect detection. A dialect is the set of rules a delimited file follows: the delimiter, the quoting style, the line ending and the character encoding.
Tabs are invisible, so a file can look tab-separated when it actually uses spaces, commas or semicolons. If the delimiter is detected wrongly, everything lands in one column or rows split in the wrong places. Opening the file read-only does not change it. Edits and saves can change it, especially in spreadsheet programs.
Before you start: protect the original
- Work on a copy of the file and keep the original unchanged.
- If you only need to look at the data, use a viewer, a text editor or a terminal command. None of these rewrite the file.
- If you open the file in a spreadsheet, avoid saving it over the original. Spreadsheets can convert values such as 02134 into 2134 or reinterpret date-like text. Saving then writes the converted values back.
Step 1: Confirm the file really uses tabs
A .tsv extension is a naming convention. It does not prove what the file contains. On Linux or macOS, the following commands show the delimiter, encoding and line endings without modifying anything. Here, data.tsv is a placeholder for your file name.
head -n 5 data.tsv
file data.tsv
cat -A data.tsv | head -n 5 # GNU/Linux
cat -et data.tsv | head -n 5 # macOS/BSD equivalent
In the cat output, each tab appears as ^I and each line end appears as $. If lines end in ^M$, the file uses Windows-style CRLF line endings. Most tools handle these, but the last field may then carry a hidden carriage return. The file command reports a guessed encoding, such as UTF-8 or ASCII, and usually says when a file has CRLF line terminators. That encoding is a guess, not a guarantee.
Illustrative example: suppose a small TSV file contains the lines below. Between the fields are real tab characters, which display as gaps. The second data row has an empty ZIP field, so two tabs sit next to each other.
id name zip joined
001 Ana Ruiz 02134 2024-03-05
002 Li Wei 2023-11-20
For that file, cat -A should produce output in this form. The space inside "Ana Ruiz" stays a space and is not a delimiter. The empty field shows up as ^I^I.
id^Iname^Izip^Ijoined$
001^IAna Ruiz^I02134^I2024-03-05$
002^ILi Wei^I^I2023-11-20$
Next, check that every row has the same number of fields. The command below counts tab-separated fields per line and summarizes the counts:
awk -F'\t' '{print NF}' data.tsv | sort | uniq -c
A clean file produces a single line, such as "3 4" for the example above: 3 lines, each with 4 fields. If more than one count appears, some rows have extra or missing tabs. Look at those rows before trusting any table view.
Step 2: Choose a way to open the file
| Method | Good for | Watch out for |
| Text editor | Quick look, small files, checking raw content | Columns rarely line up; tabs are invisible unless the editor can show whitespace |
| Terminal (column, less) | Fast read-only viewing, large files | Some versions of column merge consecutive tabs, which shifts empty fields |
| Spreadsheet import (Excel, LibreOffice Calc, Google Sheets) | Sorting, filtering, reading wide tables | Automatic type conversion can drop leading zeros and alter dates |
| Python (csv module or pandas) | Repeatable processing, very large files | Default quoting and missing-value rules may not match your file |
| Online TSV viewer | Opening a file on a device with no other software | The file is uploaded to someone else's server |
View a TSV file in a text editor
Any plain-text editor will open the file. If the editor has an option to show whitespace or invisible characters, turn it on so you can tell tabs from spaces. If accented letters or symbols show up garbled, reopen the file with a different encoding. UTF-8 is the usual first choice.
Read it as aligned columns in the terminal
column -t -s $'\t' data.tsv | less -S
This lines up the columns and lets you scroll sideways through wide rows without wrapping. The $'\t' syntax passes a literal tab in bash and zsh. Some implementations of column treat several tabs in a row as one separator, so an empty field can make later values look as if they moved left. Compare a few rows against the cat -A output if anything looks off.
Open a TSV file in a spreadsheet without changing values
Avoid double-clicking the file. Use the program's import feature instead, which lets you choose the delimiter and column types. Menu names differ between versions, so treat the paths below as general directions.
- Excel: use the Data tab's import option for text or CSV files. Set the delimiter to Tab and check the preview. To keep values exactly as written, set columns such as IDs and ZIP codes to Text, either in the import settings or in the query editor.
- LibreOffice Calc: when you open the file, a Text Import dialog appears. Tick Tab under separator options, untick the other separators, and set the type of sensitive columns to Text in the column preview.
- Google Sheets: use File, then Import, and upload the file. Under separator type, choose Tab rather than relying on automatic detection. Consider turning off the option that converts text to numbers, dates and formulas.
Check the result: the column count should match the field count from Step 1. Values such as 02134 should still have their leading zero, and the empty field in the example should appear as an empty cell in the correct column.
Read a TSV file in Python
The standard library csv module reads TSV once you set the delimiter to a tab. Opening the file with newline="" lets the csv module handle line endings itself, as its documentation recommends.
import csv
with open("data.tsv", newline="", encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
for row in reader:
print(row)
quoting=csv.QUOTE_NONE treats double quotes as ordinary characters. Many TSV files have no quoting convention at all. Without this setting, a stray quote mark can merge fields or rows. If your file does wrap fields in quotes, leave this argument out. If the file starts with a byte order mark (BOM), use encoding="utf-8-sig" so the mark is not glued onto the first header name.
With pandas, read every column as text and turn off automatic missing-value detection. Otherwise strings such as "NA" or "null" become empty values:
import pandas as pd
df = pd.read_csv("data.tsv", sep="\t", dtype=str, keep_default_na=False)
print(df.head())
print(df.shape)
If you are not sure of the delimiter, the csv module can guess it from a sample. This is a heuristic, so confirm the guess with the checks from Step 1:
import csv
with open("data.tsv", newline="", encoding="utf-8") as f:
sample = f.read(4096)
dialect = csv.Sniffer().sniff(sample, delimiters="\t,;|")
print(repr(dialect.delimiter)) # '\t' means tab-separated
Open a TSV file online
Browser-based viewers and converters can display a TSV file without installing anything. Google Sheets, described above, is one option. No specific standalone online tools were evaluated for this guide, so their delimiter detection, size limits and data handling are not confirmed here. Uploading a file sends its contents to an outside service. Don't upload files that contain personal, financial or confidential data unless you are allowed to share them with that service. After opening, run the same checks as for any other method: the column count, preserved leading zeros and empty fields in the right place.
Common problems and fixes
- Everything appears in one column: the program did not split on tabs. Re-import and choose Tab explicitly, or check with cat -A whether the file actually uses commas, semicolons or spaces.
- Columns shift in some rows: those rows have extra or missing tabs, or a field contains a tab or line break. Find them with the awk field-count command.
- Leading zeros or long numbers change: the column was read as a number. Import it as text.
- Odd characters such as é instead of é: the encoding was guessed wrong. Reopen as UTF-8, or try the encoding reported by the file command.
- The first column name has invisible extra characters: the file likely starts with a BOM. Use utf-8-sig in Python, or an import option that handles it.
- The last column has trailing invisible characters: the file uses CRLF line endings and the tool did not strip the carriage return.
Quick result check
- Every row has the same number of fields as the header.
- Empty fields appear as empty cells in the correct column, and later values have not shifted left.
- IDs, ZIP codes and other zero-padded values match the raw text exactly.
- Accented letters and symbols display correctly.
- The original file is unchanged. If you saved anything, you saved it to a copy.