我有3个文本文件的文件夹。 文件1,称之为test1.txt的具有价值遍历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
嗨,这很好,但是当我运行代码它不起作用。我必须删除第一行的文件。之后,它仍然给我一个错误。无法绑定参数'FilterScript'。无法将“System.String”类型的“Exist”值转换为键入“System.Management.Automation.ScriptBlock”。其中<<<< Exist -NE $ true。 .......它是一个PowerShell版本错误?再次感谢您的帮助! :D – Cesar
你应该更新你的PowerShell版本;) – Esperento57
或修改为:其中{$ _。Exist -NE $ true} – Esperento57