0

I have two CSV files with the same column structure; A.csv and B.csv

I'm looking for a PowerShell way to append B.csv to the end of A.csv, without the header.

3 Answers 3

1

You can just try:

Import-Csv a.csv, b.csv | Export-Csv c.csv -notype 
Sign up to request clarification or add additional context in comments.

2 Comments

Will this remove the header from b.csv before adding it to a.csv?
Yes it will, The explanation is that Import-Csv read the lines for both files a.csv and b.csv and transform each line in an object, then it writes all the objects to c.csv file.
0

I recommend the answer with Import-Csv | Export-Csv for simplicity. Just be aware that it's probably not very efficient to parse both (potentially large) files as CSV when that's not really necessary.

This example doesn't make any assumptions about the structure of the files and just takes file 2 (without the first line) and appends it to file 1:

Get-Content .\file2.txt | where ReadCount -gt 1 >> .\file1.txt

1 Comment

This answer could benefit from more explanation regarding the where ReadCount -gt 1 part of the command.
0

A variation on @JPBlanc's answer:

 $files=@("C:\temp\test\a.csv", "C:\temp20170219\test\b.csv")
 import-csv $files | export-csv -NoType "c:\temp\c.csv"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.