Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am merging (concatenating) many text files into one, but I have the problem that they don't have a new line at the end of the text.

Is there any way to append a new line to all files using Windows command or batch file?

I am using cmd.exe of Windows Vista.

share|improve this question
up vote 3 down vote accepted

You can run this as a batch file

del merged.txt

for %%I in (*.txt) do (
    echo %%~fI >> merged.tmp
    echo --------- >> merged.tmp
    type %%I >> merged.tmp
    echo. >> merged.tmp
    echo. >> merged.tmp

ren merged.tmp merged.txt

This way you don't have to specify the names but all the files must be in the same folder.

The echo %%~fI echo the full path name, for other options you can consult

help for

Other than that, if the result is not exactly as you want, probaby all you need is just changing what are echo-ed

share|improve this answer
all worked well , thanks buddy. ANy way to add name of the file in the merged file – Mirage Feb 22 '10 at 4:05
I don't know how exactly you want it, but I think my edited answer should point you in the right direction – RichN Feb 22 '10 at 4:20
thank for that , it worked – Mirage Feb 22 '10 at 4:26

You can concatentate files using COPY

For example, files: data1.txt and data2.txt can be combined by:

copy data1.txt + data2.txt dataFull.txt

and the result will be in dataFull.txt. If you leave off the destination it will all be in the first listed file.

To insure a newline the easiest, although not most elegant method would be to create a file, newline.txt, which is simply a blank line and include it after each file:

copy data1.txt + newline.txt + data2.txt dataFull.txt

It would be fairly straight forward to include this addition in a looping structure.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .