Practical workflow
Use invoice ID as a key. Duplicate IDs can be legitimate for line items, so check the business meaning before removing them. Aggregate line items only when your matching policy requires it.
Check before you automate
Save a copy of the original exports. Test on a representative sample, review exceptions and compare the result against a manually checked example. Record the rules so the process can be repeated consistently.
Try the related tool