csvkit.org
CSV (Comma-Separated Values) utilities, in the browser
Say hi →

CSV Set Operations

union · intersect · A minus B · symmetric difference · nothing uploaded

Two lists, one question: what is in both, what is only in one. Paste an old export and a new one and take the difference; paste two mailing lists and take the union without duplicates; paste a list of active users and a list of paying ones and keep the overlap. Same idea as UNION, INTERSECT and EXCEPT in SQL, on files instead of tables.

set ops
A: drop a .csv here, or
B: drop a .csv here, or
ready

CSV set operations

The operation people actually want when they say "compare two CSVs" is usually a set operation, not a diff: not what changed in this row but which rows are missing. This does the second one, and hands back a CSV you can use rather than a report you have to read.

How to use it

  1. Paste or drop file A on the left and file B on the right. Both need a header row.
  2. Pick the operation. The names in the list are the SQL ones; the descriptions next to them are what they do.
  3. Pick what to match on. Whole row means two rows are the same when every shared column matches. Pick a column instead — usually an id or an email — and only that column decides.
  4. Read the status line. It reports how many keys were in both files and how many were on one side only, which is the answer to the question even before you look at the output.
  5. Copy or Download .csv.

The six operations

Matching, and why the column matters

With whole row selected, two rows are equal when every column the two files share has the same value. Columns that only one file has are listed in the status line and left out of the comparison — otherwise every row would differ for a reason that has nothing to do with the data.

Matching on a single column is nearly always what you want when the files come from different systems. An export from billing and an export from the CRM will not agree about capitalisation, trailing spaces, or a last_seen timestamp, but they agree about the email address. Trim values and ignore case exist for the same reason: "[email protected] " and "[email protected]" are the same customer and no exact comparison will ever say so.

Duplicates

Every operation except union all emits each key once. If file A contains the same key three times, the intersection contains it once — a set has no multiplicities. When the duplicates are the point, find duplicates lists them with counts, and dedupe removes them in place.

Set operations or a diff?

Use this when the question is membership: which rows are in one file and not the other. Use CSV diff when the question is change: which cells of a matched row are different. The diff matches rows on a key and highlights the cells that moved; this hands you a file. They are answers to different questions and it is worth being clear which one you have.

For a genuine join — carrying the columns of B onto the matching rows of A — join on key is the tool. Intersect keeps A's columns only.

Privacy

100% client-side. Both files are parsed in your browser and nothing is uploaded. See the privacy policy.