Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.