8

I have the directory with 20 csv files. They all have same headers. I want to merge these csv files into one file. When I'm working on windows, I just open cmd, go to the right directory and use this command:

 copy *.csv combined-files.csv

It does the job on Windows. I can't run this command on mac's terminal as command doesn't exist on Mac. How do I rewrite this Windows command so it does the same job on Mac OS?

Lina Linutina
  • 363
  • 1
  • 2
  • 17

2 Answers2

17

Easiest I can think of, which would be similar to the Windows version is:

cat *.csv > combined-files.csv

Note that the headers would be repeated throughout the combined-files.csv if they are contained in all the .csv-files. Just like the solution you posted for Windows.

emazzotta
  • 1,879
  • 3
  • 20
  • 31
7

To concatenate all files into a single file, you can use the following awk command to consolidate the content. This will ignore the header content though

awk 'FNR > 1' *.csv > consolidated.csv

The awk command assumes that all the files are in one directory. If all of your files are in different directories, you can use the below command to bring it together into one directory

find . -name \*.csv -exec cp {} newdir/ \;
Abhishek Kumar
  • 134
  • 1
  • 3