Quickly compare two CSV files with Powershell

You can use Powershell to quickly compare two CSV files, and to see which records exist in file A, but not in file B (or vice versa).

We will use the two CSV files below as an example. Note: it is required that records in both files are sorted.

File1.csv

  • record1
  • record2
  • record3
  • record4
  • record5

File2.csv

  • record1
  • record2
  • record3
  • record5

Run “diff” tool via Powershell

  1. Open up a new Powershell window.
  2. Navigate to the directory that contains the 2 CSV files.
  3. Run this command:
    diff (cat file1.csv) (cat file2.csv)
  4. This will give the following output:
InputObject SideIndicator
----------- -------------
record4     <=

The output above indicates that the line “record4” exists in file1.csv, but not in file2.csv.

Published
Categorized as Powershell

By Leendert de Borst

Freelance software architect with 10+ years of experience. Expert in translating complex technical problems into creative & simple solutions.

Leave a comment

Your email address will not be published. Required fields are marked *