Last active
August 29, 2015 14:13
-
-
Save potatoqualitee/ec046a1995aa406eba15 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$csvfile = "C:\perf\bigperf.csv" | |
$csvfile = "C:\perf\tab.csv" | |
$csvdelimiter = "`t" # `t for tab | |
$firstrowcolumnnames = $false | |
Write-Output "Script started..." | |
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") | |
$elapsed = [System.Diagnostics.Stopwatch]::StartNew() | |
$csv = New-Object Microsoft.VisualBasic.FileIO.TextFieldParser($csvfile) | |
$csv.TextFieldType = "Delimited" | |
$csv.SetDelimiters($csvdelimiter) | |
$csv.CommentTokens = "#" | |
$datatable = New-Object System.Data.DataTable | |
Write-Warning "Filling datatable" | |
$columns = (Get-Content $csvfile -First 1).Split($csvdelimiter) | |
foreach ($column in $columns) { | |
if ($firstrowcolumnnames -eq $true) { | |
[void]$datatable.Columns.Add($column) | |
} else { [void]$datatable.Columns.Add()} | |
} | |
while (!$csv.EndOfData) {$null = $datatable.Rows.Add($csv.ReadFields())} | |
if ($firstrowcolumnnames -eq $true) { $datatable.Rows.Remove($datatable.Rows.Item(0)) } | |
$totaltime = [math]::Round($elapsed.Elapsed.TotalSeconds,2) | |
Write-Host "Total Elapsed Time: $totaltime seconds. $($datatable.rows.count) rows added." -ForegroundColor Green | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment