TOOLFRED WORKED EXAMPLE

Compare CSV files by ID, not row position

A small inventory example shows why reordered rows are different from added, removed and changed records.

By · Updated · Original examples

THE SHORT ANSWER

How do you compare two CSV files when rows move?

Match records by a stable unique key rather than row position. In the practice files, ID 003 moves without changing, 001 has a stock change, 002 is removed and 004 is added. Blank or duplicate keys must be resolved before a one-to-one comparison; the tool cannot decide which record is correct.

IDExpected comparison
001Stock changes from 8 to 10
002Removed record
003Same values, despite its new position
004Added record

Download the practice pair

Before CSV · After CSV. Both contain invented records with the columns ID, Name and Stock. IDs are text: 001 and 1 are not assumed to mean the same thing.

ID,Name,Stock
001,Desk lamp,8
002,Notebook,12
003,Pen set,24
ID,Name,Stock
003,Pen set,24
001,Desk lamp,10
004,Desk tray,6

Expected result using ID as the key

001: Stock changes from 8 to 10. 002: the record is removed. 004: the record is added. 003: no field changes; moving to the top of the file is not a change to its values. Expect one changed field, one removed record and one added record.

Open Compare CSV files, select both downloads and choose ID. Review the per-field report. A single record with several changed columns produces several changed-field entries, so report entries and distinct record totals can differ.

Resolve ambiguous keys first

A blank ID cannot reliably identify a record. Two records with the same ID do not establish which one corresponds to a later export. The comparison rejects blank or duplicate keys. Use the duplicate checker to inspect them, then consult the real source rather than deleting a row merely to pass validation.

Keep text comparisons deliberate

Values stay text: 8 and 8.0 can differ even when you would interpret them as the same number. Dates are not normalized automatically. A spreadsheet can strip leading zeroes when opening a CSV; import identifier columns as text. For different column names, deliberately prepare the mapping with the column mapper.

Review before changing production data

The report is evidence about two selected files and your chosen key. It does not confirm which version is correct or authorize an overwrite. Keep backups. Formula-like spreadsheet values can be dangerous when opened; review the tool’s safer-export option and its effect on exported text. These practice records have no real customer information.

Questions or corrections

Report a reproducible issue to contact@toolfred.com using an invented example. Avoid sensitive files. How we check tools and maintain examples →

All worked examples →