How to Combine Multiple CSV Files into One

Easily combine multiple CSV files with the Terminal on Mac.

All you need to do is:

  1. Put all the CSV files into a folder
  2. Run the following command in the Terminal at the folder:
cat *.csv >merged_file_name.csv

The above code uses the asterisks to simple grab any csv file in the folder. I find it easiest to include or exclude files in the original folder rather than specifying the name of each file in the code.

One thing to note is that this method will bring over the headers for each CSV file. To prevent that, you can either remove the headers from all but one file, or you can just remove them from the merged file.

If you aren’t familiar with the Terminal and want a quick guide on how to execute this, then read on!

Activate the Setting for Opening the Terminal at Folder

If you don’t do this step, you have to navigate your file directory in the terminal which can be tricky if you are new to the Terminal. By activating this setting, the only thing you’ll have to enter in the terminal is the above code.

On your Mac, go to Settings > Keyboard > Shortcuts > Services > Then check the box for “New Terminal at Folder”

Launch the terminal at your Folder

Find your folder in finder, right click on it, then click on “New Terminal at Folder tab”.

Run the code to merge the files

Once completed, you can open up the folder and you should see a new CSV file with the merged data!


Posted

in

by