I know I can use copy *.txt newfilename.txt
to merge all the text files in a folder. Is there a way to do this, but separate each merged file with a line break?
-
What do you mean by a line break?– DavidPostill ♦Apr 2, 2015 at 20:48
-
Say I have 2 files: one file has 3 lines: cat1 is on the first line. cat2 is on the second line and cat3 is on the third line. the second file has 1 line. hat1. how do i get it so that the merged file has hat1 on the fourth line, instead of cat3hat1 on the third line.– NewbApr 2, 2015 at 21:01
2 Answers
CMD has several commands you can use to accomplish this.
- Type will show the contents of a file
- >>textfile.txt will append the output to an existig file
- echo. will print an empty line
- FOR will allow you to execute one or more commands based on a set of criteria, such as all files in a directory
Using these 4 commands, you can construct a way to accomplish what you want.
If you do not want to automate this as it are only a few files and you are doing it once, forget about the FOR and do it manually. (much easier)
The command would be this:
type file1.txt >> newfile.txt
echo. >> newfile.txt
type file2.txt >> newfile.txt
echo. >> newfile.txt
type file3.txt >> newfile.txt
echo. >> newfile.txt
If you need to include a FOR the command would be this:
FOR %f IN (*.txt) DO type %f >> newfile.log & echo. >> newfile.log
Do note: if the newfile.txt already exists, it will only append to it, not create a new file. Delete the old first
EDIT: corrected for and changed name. tnx Techie007 for pointing that out.
-
3Except it will include
newfile.txt
in the For loop. :) Output to a different folder, or with a different extension. Also, as-is this command doesn't work due to the/F
option:The system cannot find the file *.txt.
. Apr 2, 2015 at 21:47
You can use the following command in dos
more file1.txt >> file2.txt
a blank line will get inserted after every file that is being merged,
this is useful when you have to merge a common file frequently.
further examples
more file1.dat >> output.dat
any extension with files that are of ascii characters can be merged and the original file will still be available unless you delete.
You can use the following command to merge and delete the second file.
copy file1.txt 00000.txt
more 00000.txt >> 11111.txt
del 00000.txt
you can merge any type of file extensions,
a blank line gets inserted after each file that is merged
commonly used extensions are .txt, .dat, .log, etc.,