我有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