Created
July 6, 2020 17:58
-
-
Save EdWarga/1b6a55df92774e6bc86227a9427984c1 to your computer and use it in GitHub Desktop.
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
# Read parent CSV | |
$InputFilename = Get-Content 'C:\working\splitCSV\testSplit.csv' | |
$OutputFilenamePattern = 'output_done_' | |
$LineLimit = 2000 | |
# Initialize | |
$line = 0 | |
$i = 0 | |
$file = 0 | |
$start = 0 | |
# Loop all text lines | |
while ($line -le $InputFilename.Length) { | |
# Generate child CSVs | |
if ($i -eq $LineLimit -Or $line -eq $InputFilename.Length) { | |
$file++ | |
$Filename = "$OutputFilenamePattern$file.csv" | |
$InputFilename[0] | Out-File $Filename -Force # Writes Header at the beginning of the line. | |
$InputFilename[$start..($line - 1)] | Out-File $Filename -Force -Append | |
# Original line 19 with the addition of -Append so it doesn't overwrite the headers you just wrote. | |
$start = $line; | |
$i = 0 | |
Write-Host "$Filename" | |
} | |
# Increment counters | |
$i++; | |
$line++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment