Monday, December 22, 2008

array compare

This article was Previously posted on Ying Li' 


$arrFirst = get-content First.txt
$arrSecond = get-content Second.txt

New-Item "C:\Myworkplace\ps\FirstInSecond.txt" -Type file
New-Item "C:\Myworkplace\ps\FirstNotInSecond" -Type file

Foreach ($First in $arrFirst)
{
If ($arrSecond -contains $First)
{Add-content "C:\Myworkplace\ps\FirstInsecond.txt" $First}
Else
{Add-content "C:\Myworkplace\ps\FirstNotInSecond.txt" $First}



===

PS> $a1 = 1,1,2
PS> $a2 = 1,2,1


You could force "sequence equality" by setting SyncWindow to 0:
Compare-Object $a1 $a2 -SyncWindow 0
 

No comments: