What is the most efficient way of replacing the first line of a HUMONGOUS CSV file? The files I am working with are nearly 40gb in size. I am currently reading in the header row, cleaning it up, and trying to write it back to the file. This is currently what I am doing in powershell when writing back to the file:
Import-CSV $file -Header $newHeader | Select -Skip 1 | Export-CSV -Path $newFile -NoTypeInformation
I am wondering if there is a way for me to replace that first line, without reading the entire file into memory, then writing it to a new file.
UPDATE
I have modified my script to read/write using the following:
$sr = [System.IO.StreamReader] $inputFile
$sw = [System.IO.StreamWriter] $outputFile
#Get rid of the first row
$null = $sr.ReadLine()
$Header = #my new header
$sw.WriteLine($Header)
#Write the remainder of the old file to the new report file
while($line = $sr.ReadLine()) {
$sw.WriteLine($line)
}