Remove duplicate columns from csv
i have csv "timestamp" field appearing header 3 times so:
timestamp | cpu1 | timestamp | memory1 | memory2 | timestamp | networkin | networkout | networktotal
obviously powershell doesn't what's best way go removing two of columns prior import? if manually remove them in excel problems solved isn't option me.
thanks in advance
adam
try this:
$header = 'timestamp','cpu1','timestamp2','memory1','memory2','timestamp3','networkin','networkout','networktotal' import-csv 'filename.csv' -delimiter '|' -header $header | {$_.timestamp -notmatch 'timestamp'} | select -excludeproperty timestamp2,timestamp3
that make treat file header data row, filter remove row, , select remove duplicate timestamp columns rest of data.
you can exclude original header row using -skip parameter in select-object:
import-csv 'filename.csv' -delimiter '|' -header $header | select -skip 1 -excludeproperty timestamp2,timestamp3
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Windows Server > Windows PowerShell
Comments
Post a Comment