Tuesday 21 November 2017

Concatenating CSVs the easy way

I was recently asked how to 'merge' a few CSV files into one, and if there was a script or tool that could do that.

Lets say you have 3 CSV files, called 1.csv, 2.csv and 3.csv
All you need to do is decide which CSV you want as the 'master' file (1.csv) then delete the header row from the rest.   Then simply do the following:

In Linux, Unix or OSX

cat 2.csv >> 1.csv
cat 3.csv >> 1.csv

In MSDOS, Windows or any other variant

type 2.csv >> 1.csv
type 3.csv >> 1.csv


>> on a command line means "Append to"

cat / type is simply a command to display the file

So cat 2.csv >> 1.csv is saying read 2.csv and append it to 1.csv.

No comments:

Post a Comment

Concatenating CSVs the easy way

I was recently asked how to 'merge' a few CSV files into one, and if there was a script or tool that could do that. Lets say you h...