Last Updated on November 19, 2018 by Dave Farquhar
I had a bunch of CSV files I needed to merge. I don’t spend half an hour loading all of them into Excel and doing a bunch of copying and pasting. Here’s how I merge CSV files from a command prompt.
copy /b file1.csv+file2.csv+file3.csv master.csv
That’s all there is to it. Load the resulting file into Excel, remove the duplicate header rows, and I have one big, master CSV file to work with in a matter of seconds. You can concatenate as few or as many files as you want this way. I happened to have 20, so this bit of command line trickery probably really did save me half an hour.
If manual cleanup in Excel isn’t an option, here’s another way to merge CSV files.
David Farquhar is a computer security professional, entrepreneur, and author. He started his career as a part-time computer technician in 1994, worked his way up to system administrator by 1997, and has specialized in vulnerability management since 2013. He invests in real estate on the side and his hobbies include O gauge trains, baseball cards, and retro computers and video games. A University of Missouri graduate, he holds CISSP and Security+ certifications. He lives in St. Louis with his family.
I probably would have used Type and redirect, and after the first line, filtered the header:
Type file1.csv > master.csv
type file2.csv | filter “header” >> master.csv
type file3.csv | filter “header” >> master.csv
But then I’m old skool. 😉
Er, Find /v. I forgot I wrote a batch file called “filter” that does it for me. Sigh…