1

I use below two commands to concatenate multiple files from different directories:

  1. Method 1

    type "C:\folder1\file1.txt" "C:\folder2\file2.txt" > output.txt

  2. Method 2

    copy "C:\folder1\file1.txt"+"C:\folder2\file2.txt" output.txt

However, the output file in Method 1 contains EOF at the end of every single file. How to get rid of the EOF?

4
  • What if you execute type c:\folder1\file1.txt > output.txt & type c:\folder2\file2.txt >> output.txt ? – Mark Allen Aug 17 '15 at 18:28
  • @MarkAllen it works. it doesn't have EOF in the middle of the output file – askingtoomuch Aug 18 '15 at 0:51
  • @Sun I'm using windows – askingtoomuch Jun 9 '16 at 17:25
  • @Sun Windows 8.1 Pro – askingtoomuch Jun 10 '16 at 8:48
3

Concatenate Multiple files into One File Create Test Files

E:\Work\>for %x in (1 2 3 4) do echo %x > %x.txt

        E:\Work\>echo 1   1>1.txt

        E:\Work\>echo 2   1>2.txt

        E:\Work\>echo 3   1>3.txt

        E:\Work\>echo 4   1>4.txt

Verify test file creation

E:\Work\>dir *.txt

        Directory of E:\Work\

        2017-04-26  02:53 PM                 5 1.txt
        2017-04-26  02:53 PM                 5 2.txt
        2017-04-26  02:53 PM                 5 3.txt
        2017-04-26  02:53 PM                 5 4.txt

Concatenate files

E:\Work\>copy /b ?.txt concatenation.txt

        1.txt
        2.txt
        3.txt
        4.txt
                1 file(s) copied.

Verify concatenated file creation

E:\Work\>dir *.txt

        Directory of E:\Work\

        2017-04-26  02:53 PM                 5 1.txt
        2017-04-26  02:53 PM                 5 2.txt
        2017-04-26  02:53 PM                 5 3.txt
        2017-04-26  02:53 PM                 5 4.txt
        2017-04-26  02:54 PM                20 concatenation.txt

Verify correct contents of concatenated files

E:\Work\>type concatenation.txt

        1
        2
        3
        4
1
  • Works for me: copy /b *.txt concatenation.txt – pkSML Feb 19 '19 at 3:39
1

For me it is the method 2 with COPY that causes the EOF to be added, not the TYPE way. You can tell COPY to copy the files as binary with the /B flag. Then the output will be exactly the files and nothing more.

1
  • It's strange. I'm on win8.1. COPY doesn't include any EOF in the middle of the output file. – askingtoomuch Aug 18 '15 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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