2016-07-15 3 views
0

オブジェクト現在、私はこのようになりますカスタムリストを持っている:PowerShellの - カスタムで行を組み合わせること

ItemPath ItemName LineNumber Indicator Text 
-------- -------- ---------- ---------- ------------ 
C:\  Test.txt 10   Reference Hello World! 
C:\  Test.txt 10   Difference Hell0 W0rld! 

私はこのように見えるようにリストをソートしたり再編成したい:

ItemPath ItemName LineNumber DiffText  RefText 
-------- -------- ---------- ------------ ------------ 
C:\  Test.txt 10   Hello World! Hell0 W0rld!  

基本的に私"インジケータ"に基づいてラベル付けされた "text"の値で行番号で結合された行を追加します。私はこれを考え出して運がない。グループへ

+0

はどのようにして生成/最初の場所でリストを作成しましたか? –

+0

こんにちは!私はCompare-Objectコマンドレットからの出力を得ました。 – TroggleDorf

+0

したがって、オブジェクトの名前はallComparisonsで、大きなプログラムの一部として作成しましたが、関連するコマンドは次のとおりです。 $ NewItem = @ {"ItemPath" = $ ProdPath; "ItemName" = $ ProdName; "インジケータ" = $ FormatedIndicator; "LineNumber" = $ comparison.InputObject.ReadCount; "TextString" = $ comparison.InputObject} $グローバル:allComparisons + =新しいオブジェクトpscustomobject -Property $ NewItem – TroggleDorf

答えて

1

使用Group-Objectパス、名前と行番号によってオブジェクトは、単一のオブジェクトにペアを組み合わせる:

$pairs = $allComparisons |Group-Object -Property ItemPath,ItemName,LineNumber |ForEach-Object { 

    # Grab the two objects in the group 
    $Difference,$Reference = $_.Group |Sort-Object Indicator 

    # Create a new object with Text properties from each 
    New-Object psobject -Property $([ordered]@{ 
     ItemPath = $Reference.ItemPath 
     ItemName = $Reference.ItemName 
     LineNumber = $Reference.LineNumber 
     DiffText = $Difference.Text 
     RefText = $Reference.Text 
    }) 
} 
+0

ありがとう!私はこれを試してみましょう! – TroggleDorf

+0

それは本当に私を助けました!ありがとう! – TroggleDorf

関連する問題