0

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.

2 Answers 2

3

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

2
  • all worked well , thanks buddy. ANy way to add name of the file in the merged file
    – Mirage
    Feb 22, 2010 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, 2010 at 4:20
4

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.

You must log in to answer this question.

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