Poss开发者_开发技巧ible Duplicate:
Comparing two arrays & get the values which are not common
I wanted a logic to get uncommon items from an array, for example:
$a=@(1,2,3,4,5,6)
$b=@(1,2,3,4,5,7,9,10)
I want the output $c
to be 6 which is the missing element in $b
array, priority should be only given to the array contents of $a
.
Can anyone please help me out with this?
Thanks!Either empo's approach, or
$a1=@(1,2,3,4,5,8)
$b1=@(1,2,3,4,5,6)
Compare-Object $a1 $b1 |
Where-Object { $_.SideIndicator -eq '<=' } |
Foreach-Object { $_.InputObject }
returns 8
$c = $a | ? {!($b -contains $_)}
The priority will be given to the variable you "pipe".
精彩评论