user1553605
user1553605

Reputation: 1393

Compare two CSV files in vbscript

I have to write vbscript to compare two csv files,

The both csv files contains the following data format, File1.csv

DBNane UserGroup Path                 Access
DB_1    Dev_II   DB/Source/Projects   Read/Write
DB_2    Test_I   DB/Source/Doc        Read

File2.csv

DBNane UserGroup Path                 Access
DB_1    Dev_II   DB/Source/Projects   Read
DB_2    Test_I   DB/Source/Doc        Read

I need to compare these files, the output format is like,

File3.csv

DBNane UserGroup Path                 Access
DB_1    Dev_II   DB/Source/Projects   Read/Write

I'm new to the vbscript. Any sample script to do this ? Thanks.

Upvotes: 0

Views: 2709

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

In PowerShell you could get differing lines from 2 text files like this:

$f1 = Get-Content 'C.\path\to\file1.csv'
$f2 = Get-Content 'C.\path\to\file2.csv'

Compare-Object $f1 $f2

If you only need to show what's different in the first file ($f1), you could filter the result like this:

Compare-Object $f1 $f2 | ? { $_.SideIndicator -eq '<=' } | % { $_.InputObject }

Upvotes: 2

Related Questions