Combine multiple files into one using Windows Command Prompt
Combine multiple files into a single file is very simple on Windows as long as the files you are wanting to combine are text (binary). Its not possible to merge multiple images, videos and other none binary related content using this method. Here is the Command Prompt (cmd) command we will be using to achieve this.
1 |
copy /b *.txt combined.txt |
We must use the /b attribute which tells the copy command that we are working with binary files. We then provide the file we wish to copy which in are case is “*.txt” which means every file which has the ending extension “.txt” and then the new location which is “combined.txt”.
You can replace .txt with what ever file extension is being used by your files and also change the name from combined.
Walkthrough
First we need to lunch Command Prompt (cmd) by going to “Start ->All Programs -> Accessories -> Command Prompt”.
This may differ slightly on other Windows versions as I am suing Windows 7.
Now browse to the location where the files you want to combine are stored and click on the navigation bar. It is the area highlighted in red in the image below. You want to copy the text inside by “right clicking -> Copy”.
Now go to the cmd screen we loaded up at the beginning (the black console screen) and type
1 |
cd " |
Now either right click on the console screen or press the “INSERT” key located on the keyboard just above the arrow keys to insert the text we copied earlier. Now we need to add a ending ” character.
1 |
" |
Now press the enter key (return key) and your screen should now look something like the following.
We have now moved the cmd window into the directory where we have stored the files we wish to combine. All you now have to do is run the copy command located at the top of this post. Here is an example of how my screen looked once I had run the copy command above but replaced the .txt with .log.
I now have a new file called combined.log which contains all the contents from the other files but in the single file.
partha
Thank a lot
really this is a helpful things ..
using this command not only .txt file any type file are merged
ECN
Hi!
I have many files in .txt, and each file contains many data in the same format. In each file, each data are separated by “enter”. I want to combine all txt file into one file with each file name at the end of each data. Example: if I have below data
– file1.txt:
9,1,1,1
1,8,1,2
3,2,1,4
– file2.txt:
2,1,4,1
3,1,1,2
0,2,4,5
And I want to combine to 1 txt file like this:
9,1,1,1,file1
1,8,1,2,file1
3,2,1,4,file1
2,1,4,1,file2
3,1,1,2,file2
0,2,4,5,file2
Please help.
Jill
Oh, my goodness! This saved me a TON of work!! Thanks a bunch!!
Shane Rutter
Glad it was helpful for you 🙂
Malcolm
Thanks for the very clear explanation. A colleague was having issues with a huge non-standard text file. We managed to wrangle it into shape by splitting it up and then processing each fragment, then reassembling was super easy thanks to these instructions, and no need to download any software.
Shane Rutter
Glad you found it helpful.
Rajorshi Roy
if you use this command, the files are concatenated in the following order:
1,10,11,12,13….18,19, 2,21,22…..27,28,29, 3,31,32……………….
which is wrong.
how do I concatenate the files in the correct order, i.e.:
1,2,3,4…8,9,10,11,12….18,19,20,21,22,…………………….
saurabh
This worked. Thanks. I also need file name against each data set. For instance, file name 1 in first column and then data in subsequent columns. How can we get this.
rundekugel
thanks, you helped me, since I also google, before using “man copy” or in case of windows
copy /?
I did “copy /?” after reading your artikle and this helped me, to pick some files, which I want to add with:
copy /b file1.dat +file88.dat +file1.dat comb.dat
This helps also in some seldom cases to add the same file multiple times.
Benny
Why is the “/b” binary option required if we are not combining binary files? The instructions state that it is not possible to combine binary files, but it says we must use the binary option for some reason.
Thank you,
Benny
Shane Rutter
With it being text files you can combine using /a or /b, it does not make much difference. However combining most binary files types will normally fail or cause inconsistencies, for example if you tried to combine two MP3 songs, the track records most probably wouldnt be correct as it would believe the songs 3 minutes long, but its really 6 minutes long, and most binary files just wont work after combining in this manner.