Windows PowerShell Home
Export-Csv -Append validation
9/16/2013 8:39:09 AM
User(s) can reproduce this bug
The Append switch (introduced in v3) allows us to add the content of one CSV file to the end of another CSV file.
This is working great ONLY if the destination file ends with a line break.
How often does this happen?
Have you seen this problem before in this product?
Yes, this happens in previous released versions
Consider the following two files:
## one.csv ##
## two.csv (destination file, no new line after the last record) ##
Now, if you append the content of one.csv to two.csv you corrupt the data on the second file. PowerShell doesn't check if the file ends with a line break and just appends the content as is.
PS> ipcsv .\one.csv | ft -a
PS> ipcsv .\two.csv | ft -a
## merge the files and check the content:
PS> ipcsv .\one.csv | epcsv .\two.csv -append
PS> ipcsv .\two.csv |ft -a
to post a comment.
Please enter a comment.
Joel 'Jaykul' Bennett
on 9/16/2013 at 9:15 AM
The csv cmdlets really need some tender loving care, bearing in mind that CSV support is all about INTEROPERABILITY, not about temporary storage from PowerShell. That is: we need to be able to create/open these files in other editors and edit them without breaking things: any CSV file output from excel (or notepad) should work.
Obviously that might you don't have the trailing newline, so the cmdlet should always make sure it's there when it starts to append.
In an ideal world, you'd even get a warning if the new output didn't match the columns of the original output...
to post a workaround.
Please enter a workaround.
© 2014 Microsoft