powershell导入csv,删除行+更改标题行并导出回csv

时间:2016-05-19 09:35:29

标签: csv powershell

我有以下形式的csv:

original csv

我想要实现的是导入csv,删除所有行,直到第二个标题行,并且这次使用新标题将其导出回csv。

我已经写了以下内容,但似乎无法发挥作用:

$csvimport = get-content C:\Win12simpleExpComp.csv
$firstline = "Header1, Header2, Header3, Header4"
$csvpre = $csvimport.Where({ $_ -like "$firstline" },'SkipUntil');
$csvpre | Export-Csv -NoTypeInformation C:\export.csv

我在导出的csv中获得的内容如下:

PSPath,"PSParentPath","PSChildName","PSDrive","PSProvider","ReadCount","Length"
C:\Win12simpleExpComp.csv,"C:\","Win12simpleExpComp.csv","C","Microsoft.PowerShell.Core\FileSystem","39","205"

1 个答案:

答案 0 :(得分:0)

而不是:

$csvpre | Export-Csv -NoTypeInformation C:\export.csv

执行:

$csvpre | Out-File C:\export.csv