THE DATA DESK · 01
How to compare two CSV files by a unique ID
When rows move, line-by-line comparisons get noisy. Match two CSV exports by a stable, unique ID to see which records changed.
Compare two small exports
Download before.csv and after.csv. Choose Compare two CSVs, open before.csv as A and after.csv as B. id is suggested as the match column because it is filled and unique in both files; the differences appear straight away.
File A
id,name,city 001,Rae,Boston 002,Jin,Seattle 003,Ana,Chicago
File B
id,name,city 001,Rae,Boston 002,Jin,Portland 004,Leo,Denver
Expected: 3 differences. ID 001 is unchanged.
| Key | Status | Meaning |
|---|---|---|
| 002 | Changed | city: Seattle → Portland |
| 003 | Only in A | Ana is missing from the newer export |
| 004 | Only in B | Leo appears in the newer export |
Reordering either file does not change the match. A duplicate or empty ID stops the comparison because the tool cannot select the correct record reliably.
Clean the file before matching
Download messy.csv. In “Clean a CSV”, open it and keep the three clean-up steps on (“Trim extra spaces”, “Remove empty rows”, “Remove duplicate rows”). The duplicate is an exact copy, so matching by the entire row or by id gives the same result. Removed rows stay visible, struck through, with the line they repeat.
Expected: 3 output rows, 1 duplicate removed, and 1 blank row removed.
Deduplication keeps the first matching row, or the last if you set Keep to the last copy. Review conflicting duplicates before using a key: two records with the same ID and different names will not be merged. The header row is retained; trimming applies to data cells. More cases, including matching by one column and ignoring case, are in removing duplicate rows from a CSV.
What this workbench compares
- Files are CSV or TSV, up to 15 MB each. UTF-8 and UTF-16 are read directly; a file that is not valid UTF-8 is read as Windows-1252, and other encodings (Shift_JIS, GBK, Big5, Windows-1251 and more) can be picked under Separator & encoding. Downloads are UTF-8. Commas, tabs, semicolons and pipes are detected; the cleaned CSV uses commas unless you choose another output separator (see changing the delimiter).
- Quoted commas, quoted line breaks, escaped double quotes, and a UTF-8 BOM are supported.
- Each file needs a header with distinct, nonempty column names. Short rows are filled with empty cells and marked; a row with extra filled cells pauses the download and is named by line number.
- Only columns with exactly matching names are compared. Unmatched columns are listed separately; they are not silently compared by position.
- Match keys are trimmed. Other cells compare as text, so
1differs from1.0and trailing spaces can matter. Tick Ignore upper/lower case or Ignore spaces at the start or end when one export changes capitalisation or padding; rows that differ only in those ways then count as unchanged. - The preview shows 400 rows. The download includes every result row. This is a CSV tool, not an Excel workbook or formula engine.
- In the downloaded differences report, cells that start with
=,+,-or@(other than plain numbers) get a leading apostrophe so a spreadsheet does not run them as formulas.
Your files are processed locally in the browser. Neither the optional consent-based analytics nor Cloudflare Web Analytics, which counts visits, receives file contents. Read the privacy notice.
Reference
RFC 4180 — common CSV format. The examples describe this tool’s behavior; verify the requirements of your own system before using an output.