【发布时间】:2013-06-26 09:48:46
【问题描述】:
我正在使用 powershell 脚本将数据附加到一堆文件的末尾。 每个文件是一个大约 50Mb 的 CSV(比如 200 万行),大约有 50 个文件。
我正在使用的脚本如下所示:
$MyInvocation.MyCommand.path
$files = ls *.csv
foreach($f in $files)
{
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($f)
$year = $basename.substring(0,4)
Write-Host "Starting" $Basename
$r = [IO.File]::OpenText($f)
while ($r.Peek() -ge 0) {
$line = $r.ReadLine()
$line + "," + $year | Add-Content $(".\DR_" + $basename + ".CSV")
}
$r.Dispose()
}
问题是,它很慢。通过它们大约需要12个小时。 它不是超级复杂,所以我不希望它需要那么长时间才能运行。 我可以做些什么来加快速度?
【问题讨论】:
标签: powershell csv