404 Tech Support

Merge multiple .txt files into a single file through the command line

When working with a lot of data and trying to massage it into usefulness, you never know what form the data will take. I recently wound up with a directory full of text files. In an effort to save some tediousness of the task, I looked for a way to merge all the files into one simple text file. With a single file, I could set to cleaning up the data using find and replace before importing it into an Excel spreadsheet or database.

The command is incredibly simple. It just uses the copy command to copy multiple files into a new one using a wildcard for the filename

copy \\server\share\*.txt \\server\share\merge.txt

It can also be run locally, it doesn’t have to be on a server share. You can also change format or merge other text formats besides .txt like a comma-separated file. You could even use the command to merge various file types into a single file by using the wildcard like *.* to replace the file extension.

Knowing this beforehand may help you generate the output in a way you need it for easier manipulation but at the very least getting down to one file should make the task far more manageable.