-1

I got multiple csv files, all with the same header, all in the same folder which I have to combine to create one large csv file. Since every .csv-file has the same header, I guess using it once should be enough.

All files look like this (also delimited by ','):

Header1,Header2,Header3
Data1, Data2, Data3
Data4, Data5, Data6

Can you help out? I'm not very comfortable with Powershell yet, tried out different codes but nothing really helped me out.

Thanks

KevinD
  • 103
  • 1
  • 1
  • 6

3 Answers3

1

if all csv's has the same columns, simply:

# Original CSV
$csv = import-csv c:\temp.csv

# 2nd CSV
$csv2 = import-csv c:\temp2.csv

# As simple as:
$csv += $csv2
Avshalom
  • 8,657
  • 1
  • 25
  • 43
0

If you want to import all CSV's in the current folder you can do something like the following:

Get-ChildItem *.csv | % { Import-Csv $_ }
DanL
  • 1,974
  • 14
  • 13
-1

start by copying the first file to an output file.

then see this (question, answer): https://stackoverflow.com/a/2076557/1331076 it shows you how to remove the first line from a file. you would have to modify it, so instead of replacing your existing file, you Add-Content to the output file.

Community
  • 1
  • 1
Henrik
  • 2,180
  • 16
  • 29