Skip to content
TheSpreadFix

How to Compare Two CSV Files

Updated

When you have two versions of a dataset — last month's export and this month's, a source file and a migrated file, or two CRM exports from different dates — you need to know exactly what changed. This guide covers three approaches, from manual to automated.

Why you need to compare CSV files

  • Detecting changes between periodic exports — which contacts were added, updated or removed since the last pull.
  • Validating a data migration — confirming that every record made it from the old system to the new one with the correct values.
  • Auditing edits — a colleague modified the file and you need to see what they changed before importing.
  • Debugging an import — comparing the file you uploaded with the data the system actually stored.

What 'compare' means for CSV files

Unlike comparing two text documents line by line, comparing CSV files is usually row-based. You pick a key column (email, ID, SKU) that uniquely identifies each record, then the comparison answers three questions: which rows exist only in file A, which exist only in file B, and which exist in both but have different values in other columns.

Without a key column, comparison falls back to line-by-line text diffing, which breaks when rows are reordered even if the data is identical.

Method 1: manual comparison in Excel

  1. Open both files in Excel and paste them into two sheets in the same workbook.
  2. Sort both sheets by the key column (for example email) so rows are in the same order.
  3. To find rows in Sheet1 missing from Sheet2, add a column in Sheet1 with =ISNA(VLOOKUP(A2,Sheet2!A:A,1,FALSE)). TRUE means the row doesn't exist in Sheet2.
  4. To find changed values, use =IF(B2<>INDEX(Sheet2!B:B,MATCH(A2,Sheet2!A:A,0)),"CHANGED","") for each data column, where column A is the key.
  5. Conditional formatting can highlight differences, but with large files the formulas become slow and hard to maintain.

This works for small files (under a few thousand rows) but is tedious and error-prone for larger datasets.

Method 2: text diff tools

Tools like WinMerge, VS Code's built-in diff, or the Unix diff command can compare CSV files as plain text. They highlight added, removed and changed lines. However, they compare lines, not records — if the row order differs between files, every line shows as changed. Sort both files by the same key first, and be aware that whitespace or encoding differences can produce false positives.

Method 3: use TheSpreadFix

TheSpreadFix's CSV comparison tool lets you upload two files, choose the key column, and instantly see which rows were added, removed or changed. It matches records by key rather than by position, so reordered files are handled correctly. Changed cells are highlighted so you can see exactly which fields were modified, and the results are downloadable as a single annotated file.

Tips for accurate comparisons

  • Normalise both files first — trim spaces, standardise case and date formats — so formatting differences don't show as false changes.
  • Use a truly unique key. Names are not unique; emails or IDs are.
  • When comparing large files (100k+ rows), avoid the Excel formula approach — it becomes extremely slow. Use a dedicated tool or script.
  • Keep the original files untouched and work on copies, so you can re-run the comparison after fixing issues.

Frequently asked questions

Can I compare files with different column orders?

Yes, if you compare by column name rather than position. TheSpreadFix matches columns by header, so column order doesn't matter. In Excel, you would need to reorder the columns manually first.

What if my files don't have a unique key column?

Combine columns to create a composite key — for example, first name + last name + company. If no combination is unique, you may need a line-by-line text diff instead.