【发布时间】:2016-12-14 21:09:20
【问题描述】:
我有一个包含 3 个文本文件的文件夹。 文件 1,称之为 test1.txt 有值
11
22
22
test2.txt 有值
11
22
22
33
test3.txt 有值
11
22
22
33
44
44
我怎样才能让我的最终结果等于(New.txt) 成为:
44
44
这个值不在其他 2 个文件中,所以这是我想要的。
到目前为止的代码:
$result = "C:\NonDuplicate.txt"
$filesvalues=gci "C:\*.txt" | %{$filename=$_.Name; gc $_ | %{[pscustomobject]@{FileName= $filename; Row=$_ }}}
#list file where not exists others file with same value
$filesvalues | % {
$valtockeck=$_
[pscustomobject]@{
Val=$valtockeck
Exist=$filesvalues.Where({ $_.FileName -ne $valtockeck.FileName -and $_.Row -eq $valtockeck.Row }).Count -gt 0
}
} |
where Exist -NE $true |
% {$_.Val.Row | out-file $result -Append}
这是错误:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "Exist" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At line:16 char:23
+ where <<<< Exist -NE $true |
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
【问题讨论】:
标签: shell powershell