bat file to merge text files

Posted on 2007-10-08
Last Modified: 2008-09-11

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

Question by:chetan1981
    LVL 6

    Assisted Solution

    LVL 23

    Assisted Solution

    by:Ashish Patel
    Use copy command in your batch file like below
    Copy File1 + File2 OutputFile
    LVL 3

    Accepted Solution

    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%


    Expert Comment

    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

    Expert Comment

    how would i merge a file header.txt to all *.txt files in the same directory?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now