Michael Asgian
Michael Asgian

Reputation: 203

Appending a CSV file to end of another using PowerShell

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.

Upvotes: 0

Views: 3449

Answers (3)

JPBlanc
JPBlanc

Reputation: 72612

You can just try:

Import-Csv a.csv, b.csv | Export-Csv c.csv -notype 

Upvotes: 1

Esperento57
Esperento57

Reputation: 17462

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"

Upvotes: 0

user2226112
user2226112

Reputation:

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

Upvotes: 0

Related Questions