Powershell比较对象输出到文件

时间:2018-11-27 15:54:23

标签: powershell

我有2个简单的文本文件,需要比较并输出两个文件中的项目

Archive.TXT

10000
10001
10002
10003
10005
10010
10011

Active-Job-List.TXT

10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012

这将给我输出

$File1 = Get-Content C:\Archive-List.txt
$File2 = Get-Content C:\Active-Job-List.txt



   Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 -IncludeEqual -ExcludeDifferent | Select @{Expression={$_.InputObject}} | Set-Content C:\Diff.txt

在Diff.txt中的

@{$_.InputObject=10000}
@{$_.InputObject=10001}
@{$_.InputObject=10002}
@{$_.InputObject=10003}
@{$_.InputObject=10005}
@{$_.InputObject=10010}
@{$_.InputObject=10011}

但是我真正想要的是这个的输出

10000
10001
10002
10003
10005
10010
10011

如何将结果过滤到所需的内容?我应该Get-Content evaluate <- function(actuals, predictions){ cf.matrix <- table(actuals,predictions) cf.precision <- cf.matrix[2, 2] / sum(cf.matrix[, 2]) cf.prop_miss <- cf.matrix[2, 1] / sum(cf.matrix[2, ]) cf.accuracy <- (cf.matrix[1, 1] + cf.matrix[2, 2]) / sum(cf.matrix) cf.TruePositiveRate <- cf.matrix[2,2] / sum(cf.matrix[2, ]) cf.FalsePositiveRate <- cf.matrix[1, 2] / sum(cf.matrix[1, ]) cf.prevalence <- sum(cf.matrix[2, ]) / sum(cf.matrix) output <- list(cf.matrix,cf.precision,cf.prop_miss,cf.accuracy,cf.TruePositiveRate,cf.FalsePositiveRate,cf.prevalence) names(output) <- c('confusion matrix','precision','percent missed','accuracy','True Positive', 'False Positive', 'prevalence') return(output) } 并“修剪”我不想要的东西,还是有一种更简单的方法?

2 个答案:

答案 0 :(得分:2)

您可以像这样在命令中添加-PassThru

Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 -IncludeEqual -ExcludeDifferent -PassThru | Set-Content C:\Diff.txt

答案 1 :(得分:2)

您需要扩展 InputObject属性。

Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 -IncludeEqual -ExcludeDifferent | 
    Select-Object -ExpandProperty InputObject | 
    Set-Content C:\Diff.txt