This one is more for me to remember, but it may benefit someone trying to accomplish the same in DOS.

A task I frequently have to do is concatenate a large number of text files under windows, which up until now I’ve done using:

c:\type *.txt > output

This produces a single file called output with the contents of all text files combined together.   Unfortunately, using this method, unless each text file ends in a new line, then the last line of each file is joined with the  first line of the new file.

For example – consider two text files with the contents:

1

2

3

4

and

5

6

7

8

Running the above command would result in:

1

2

3

45

6

7

8

 

There’s a way around this though:

for %f in (*.txt) do type “%f” >> output & echo: >> output

This should save me a heap of time going through the output and manually adding new lines where needed!   Hopefully it’ll help someone else reading this too..