View Single Post
Old 07-06-2007   #1 (permalink)
Marco Shaw


 
 

Compare 2 files with 6,000 entries each

I've got one text file, and one csv file. As per a previous thread, I
wasn't able to figure out how to use compare-object to get all the
matches from each file (Keith pointed out that I'd need -synchWindow to
compare > 100 lines, but I haven't tried it yet).

The only way I've found to match up each file is to load each file:

$txt=get-content users.txt
$csv=import-csv users.csv

Then do something *ugly* like this:

$matches=$csv|%{$user=$_;$txt|%{if($_.contains($user)){$_}}}

So I loop through each entry in $csv, assign the current value to $user,
then loop through each entry in $txt looking for a match.

It is taking a *long* time...

Any performance improvement hints? If the above ever finishes, I'll
give compare-object a spin.

Marco
My System SpecsSystem Spec