commafield.

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.

KeyStatusMeaning
002Changedcity: Seattle → Portland
003Only in AAna is missing from the newer export
004Only in BLeo 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.

Open the compare workbench ↗

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

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.