私の入力ファイル (csv) は次のように読み取られます。
$recvCSV = Import-Csv $g_inputFile
以下のようになります。アドレス列は MAC アドレスを示しており、先頭のゼロを保持したいと考えています。
currentTime, SeqNum, Address, Location
1382393056692, 0,
1382393056860, 0, 38:1c:4a:0:8d:d
1382393057194, 1,
1382393057360, 1, 38:1c:4a:0:8d:d
私の出力は次のようになります。
38:1c:4a:00:8d:0d
これらは、先行ゼロを取得するための私の試みです:
$recvCSV | ? { $null, '' -notcontains $_.Address } | Group-Object Address | % { "{0:00 0:00 0:00 0:00 0:00 0:00}" -f $_.Name }
$recvCSV | ? { $null, '' -notcontains $_.Address } | Group-Object Address | % { "[string]::format "0:00 0:00 0:00 0:00 0:00 0:00", $_.Name }
$recvCSV | ? { $null, '' -notcontains $_.Address } | Group-Object Address | % { "0:00;0:00;0:00;0:00;0:00;0:00" -f $_.Name }
以下のサイトを参考にしました。
http://blog.stevex.net/string-formatting-in-csharp/
http://msdn.microsoft.com/en-us/library/fbxft59x.aspx
http://jdhitsolutions.com/blog/2012/01/format-leading-zeros-in-powershell/
私が間違っていることを教えてください。
編集:私の主な関心事は、ゼロが正しい場所に挿入されるようにする方法です(90対09)? 以下にいくつかのサンプルを示しました。
38:1c:4a:__:8d:_d ==> 38:1c:4a:00:8d:0d
__:9_:4c:11:22:33 ==> 00:90:4c:11:22:33