bat file to merge text files


How do I merge two text files into a single file. I am trying to write a bat script for that.

Who is Participating?
rberenyConnect With a Mentor Commented:
Put either of this code in a .bat file.

This will prompt you for the three file names:
@echo off
echo Please Enter the First File:
set /p file1=
set file1 2> nul

echo Please Enter the Second File:
set /p file2=
set file2 2> nul

echo Please Enter the Destination File:
set /p dest=
set dest 2> nul

type %file1% > %dest%
type %file2% >> %dest%

If you do not want a prompt but to hard code the file names use this:
@echo off
set file1=h1.txt

set file2=h2.txt

set dest=new.txt

type %file1% > %dest%
type %file2% >> %dest%

Ashish PatelConnect With a Mentor Commented:
Use copy command in your batch file like below
Copy File1 + File2 OutputFile
I have tried the above and gets the right output into the result file. How would you do it if you needed the out put to be presented like this in the result file??


I need the 2 outputs to be listed with output1/output2
how would i merge a file header.txt to all *.txt files in the same directory?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.