bat file to merge text files

Hi,

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

Thanks
chetan1981Asked:
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
cls
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
cls
set file1=h1.txt

set file2=h2.txt

set dest=new.txt

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

0
 
Ashish PatelConnect With a Mentor Commented:
Use copy command in your batch file like below
Copy File1 + File2 OutputFile
0
 
broesteCommented:
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??

output1/output2

I need the 2 outputs to be listed with output1/output2
0
 
nmcllcCommented:
how would i merge a file header.txt to all *.txt files in the same directory?
0
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.