"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:eOmJPg$vHHA.1164@TK2MSFTNGP02.phx.gbl...
> 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)){$_}}}
It will be difficult to avoid having 36,000,000 comparisons (6,000 lines
compared to 6,000 lines each). The simplest way I can express it in
PowerShell is this:
PS> gc file1.txt | ? {(gc file2.txt) -contains $_}
If the files have very different sizes, replace file1.txt with the biggest
file and replace file2.txt with the smallest one.
If file2.txt is still quite big, too big to be read from disk everytime, you
can save some cycles by assigning it to a variable first:
PS> $ref = gc file2.txt; gc file1.txt | ? {$ref -contains $_}
Hope that helps... Very late here, so I'd rather go sleep...
Jacques