How to Compare Two CSV Files and Find What Changed

To compare two CSV files, get them into the same row order and the same delimiter, then diff them side by side so each changed row lines up with its old version. Skip the first part and the diff is mostly useless: two exports of the same table, one sorted by ID and one by name, can show every single row as changed.

Below is what to normalize, the tools for each job, and a price-list export compared before and after sorting. Our CSV compare page does the side-by-side part in your browser.

Why two exports of the same table can look nothing alike

CSV looks simple, but it has no single strict standard. The closest thing is RFC 4180, and plenty of real-world files do not follow it. Two exports of the same table can differ in delimiter, quoting, line endings and row order while holding exactly the same records, and a plain line-based diff such as the diff command reports every one of those differences.

Decide one thing before you start: does row order mean anything here? For most exports it does not. The same records sorted by name and sorted by ID are the same data, but a line diff sees nearly every row move. If the rows have a stable key such as an ID or SKU, sort both files by it first.

Looks like a change, usually isn't
Highlighted in the diffReal change?Next step
Rows in a different orderNo, if the data is the same setSort both files by a key column
Comma vs semicolon delimiterNo, same fieldsNormalize to one delimiter
Cable tray vs "Cable tray"No, quoting is optional hereNormalize quoting
CRLF vs LF line endingsNoNothing in the browser; run dos2unix before a command-line diff
A trailing empty lineNoTrim it
A cell value changedYesInvestigate, this is real

The delimiter row catches a lot of people, especially across regions: many European locales use a semicolon because the comma is the decimal separator. Same data, different separator. If you want the detail on how browsers and tools read tabular text, MDN's note on reading files in the browser is a useful starting point.

Ways to compare CSV

File size and whether you need to slice the data afterwards decide most of this.

MethodGood forHandles row order?
Online side-by-side diffExports of up to a few thousand rowsNo, sort first
Spreadsheet with a lookupFiltering and pivoting the differencesYes, by matching on a key
sort then diffFiles on disk, scriptsYes, that is the point of the sort
csvkitLarge files, reordering columns by nameYes, with csvsort

Sorting is the step people skip, so do it before anything else. For a small export you can paste the data rows (everything below the header) into our sort lines tool, then put the header back on top.

Comparing two CSV exports, step by step

This is how I check two exports of the same table, usually a price list or a customer report pulled on different days.

  1. Check that both files use the same delimiter and the same header row.
  2. If row order does not matter, sort the data rows of both files the same way, keeping the header on line one.
  3. Open the CSV compare tool and put the older export on the left, the newer one on the right.
  4. Click Format on each side. It removes a byte-order mark, an invisible character some spreadsheet apps put in front of the first header and that otherwise flags the whole header row. Windows and Unix line endings need nothing: the editor treats them as the same.
  5. Check the badge above each pane: a row with a different number of columns than the header is reported by row number, usually a stray comma or an unclosed quote.

The comparison uses Google's diff-match-patch and pairs each edited row with its original, so in a changed row only the cells that differ are highlighted.

A worked example: a weekly price list

Monday's export from the shop admin, sorted by SKU:

sku,name,price,stock
A-1001,"Desk lamp, brass",49.00,12
A-1002,Cable tray,18.50,40
A-1003,Monitor arm,89.00,0

Friday's export, pulled from a different screen that sorts by product name:

sku,name,price,stock
A-1002,Cable tray,18.50,37
A-1001,"Desk lamp, brass",44.00,12
A-1004,Footrest,32.00,25
A-1003,Monitor arm,89.00,0

Compared as they are, the rows do not line up and most of the file looks rewritten. Sort the data rows of both by SKU and three changes are left:

What changed in the price list
SKUColumnMondayFridayChange
A-1001price49.0044.00Modified
A-1002stock4037Modified
A-1004whole row–Footrest, 32.00, 25Added
A-1003–––No change (moved)

The stock change is three sales during the week and needs nothing. The footrest is a new product. The lamp's price going from 49.00 to 44.00 is the one somebody has to explain, and it is a single changed cell that would be easy to scroll past in an unsorted diff.

Sorting on the command line

For files on disk, keep the header where it is and sort everything after it:

(head -n 1 monday.csv; tail -n +2 monday.csv | LC_ALL=C sort) > monday.sorted.csv
(head -n 1 friday.csv; tail -n +2 friday.csv | LC_ALL=C sort) > friday.sorted.csv
diff monday.sorted.csv friday.sorted.csv

The LC_ALL=C part is worth keeping. Without it, sort follows the machine's locale, and two people sorting the same file on differently configured laptops can get different orders. If the columns are also in a different order, csvkit's csvcut can pick them out by header name before you sort.

Delimiters, quoting, and the messy reality

Real CSV files break the rules constantly. A field that contains a comma must be quoted, so "Desk lamp, brass" is one field, not two. Quotes inside a quoted field are doubled: "She said ""hi""". And the separator itself varies: spreadsheets in comma-decimal locales export with semicolons, and tab-separated files (TSV) are common in data pipelines. Before comparing, make sure both files use the same delimiter and the same quoting convention, or normalize them with a parser that follows RFC 4180. Otherwise the diff is comparing two different dialects, not two versions of the same data.

Small things that wreck a CSV diff

ProblemWhy it happensFix
Mismatched delimitersComma vs semicolon makes every field look differentNormalize to one delimiter first
BOM at the startA hidden byte-order mark changes the first header cellStrip the BOM before comparing
Leading-zero IDsA spreadsheet may have turned 007 into 7Keep ID columns as text; compare as strings
Embedded newlinesA quoted field can contain a line break, shifting every later rowUse a real CSV parser, not a line split
Trailing spaces in cellsInvisible spaces show as a changeTrim cell values before comparing

When a spreadsheet is the better tool

A text diff is perfect for spotting which rows changed and reviewing the change as data. But if you need to filter, pivot, or compare by formula across thousands of rows, a spreadsheet is the better fit: import both files, line them up by key, and use a lookup to flag mismatches. The two approaches complement each other. Use the diff for a fast visual read and the spreadsheet when you need to slice the data. For the underlying format rules either way, Wikipedia's CSV overview is a solid reference.

Related tools

CSV is rarely the only format you handle. If the same data also lives as JSON, JSON compare can format both sides and sort the keys. Deduping a column of values is quick with remove duplicate lines, and putting rows in a predictable order before a diff is what sort lines is for. For a TSV or a plain-text report that does not need CSV handling, our main text compare tool works the same way.

Frequently asked questions

Is it OK to paste a customer or sales export into an online CSV diff?
On comparetext.org the comparison happens in your browser tab, and the files are not stored or sent anywhere unless you press Share, which saves both panes to make a link. That said, follow your company's data rules: if an export holds personal data you are not allowed to copy around, trim it to the columns you need, or compare it locally with sort and diff.
Why does my CSV diff show every row as different?
Two usual causes: the rows are sorted differently, or the delimiter differs (commas in one file, semicolons in the other). Make sure the delimiters match and sort the data rows of both files by a key column. Line endings are not the problem on the CSV compare page, which treats Windows and Unix line breaks as equal. If only the header row is flagged, click Format to remove a byte-order mark.
How do I compare two CSV files while ignoring row order?
Sort both files by a stable key column before comparing. If the rows have an ID, sort on that; otherwise sort the whole row. Keep the header line in place and sort only the data rows. In the browser you can paste the sorted versions; on the command line, sort the file after the header. Once both files are in the same order, only the rows that actually changed show up in the diff instead of every row that simply moved.
Why does my CSV use semicolons instead of commas?
Many European locales use the comma as the decimal separator, so spreadsheet apps export CSV with a semicolon delimiter instead to avoid ambiguity. The data is the same; only the separator differs. Before comparing two files, make sure they use the same delimiter, or you will see every field flagged as changed. Normalizing both to commas (or both to semicolons) with a CSV-aware tool fixes it. Tab-separated files have the same issue with a different separator.
How do I compare CSV files with different column orders?
A plain text diff compares rows left to right, so reordered columns look like a total change even when the data matches. To handle it, reorder the columns to match in both files first, or use a CSV-aware tool that compares by header name rather than position. Command-line tools like csvkit can select and reorder columns by name. Once the columns line up in the same order, a normal row-by-row diff works again.
How many rows can I compare in the browser?
A few thousand rows compare as you type, which covers most weekly reports and price lists. The page matches whole rows before it looks at individual characters, so it stays responsive. For exports with hundreds of thousands of rows, load both into a database or use csvkit with sort and diff on the command line; a browser has to draw every row, and that becomes the slow part.

Sorted both exports? Paste them into the CSV compare tool to see which rows and cells changed.