如何重组Powershell的比较对象输出? [英] How can i reorganise powershell's compare-object output?
本文介绍了如何重组Powershell的比较对象输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将2个CSV与compare-object cmdlet进行比较:
I'm comparing 2 CSV with the compare-object cmdlet :
Compare-object $CSV1 $CSV2 -property Header, Value -passthru | sort-object Header
比较2个CSV后,我得到以下输出:
After comparing 2 CSVs, i ended up with the following output :
Header Value SideIndicator
------- ----- -------------
String1 Value 1 <=
String1 Value 2 =>
String2 Value 3 <=
String2 Value 4 =>
String3 Value 5 =>
String4 Value 6 <=
我想将其重组为以下格式
I'd like to reorganise it to the following format
Header1 Old Value New Value
------ --------- ---------
String1 Value 1 Value 2
String2 Value 3 Value 4
String3 NA Value 5
String4 Value 6 NA
在PowerShell中可行吗?
Is that doable in powershell ?
推荐答案
您可以尝试:
$a = Compare-Object (Import-Csv 'C:\temp\f1.csv') (Import-Csv 'C:\temp\f2.csv') -property Header,Value
$a | Group-Object -Property Header | % { New-Object -TypeName psobject -Property @{Header=$_.name;newValue=$_.group[0].Value;oldValue=$_.group[1].Value}}
这篇关于如何重组Powershell的比较对象输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文