1

Basicly all I'm trying to do is merge 2 text files together so that each line from both files ends up next to eachother. I've been Googling it for at least 2 hours and also found this on SO:

Merge 2 txt files in a single tab delimited file in batch

For the sake of simplicity I'll paste the solution here:

@echo off

 set f1=1.txt
 set f2=2.txt
 set "sep=  "  % tab %

 (
   for /f "delims=" %%a in (%f1%) do (
      setlocal enabledelayedexpansion
       set /p line=
       echo(%%a!sep!!line!
      endlocal
   )
 )<%f2%

pause
goto :eof

The only issue is that this just outputs the result on the screen. It doesn't put it in a file and it also adds a tab seperator. When it comes to batch scripts, I really have no idea what I'm doing! So could anyone please help me out by getting the output into a file and without adding any seperators? Thanks in advance :)

Community
  • 1
  • 1
icecub
  • 8,615
  • 6
  • 41
  • 70

1 Answers1

2

This should work:

@echo off
set f1=1.txt
set f2=2.txt
set outfile=mix.txt
type nul>%outfile%
(
    for /f "delims=" %%a in (%f1%) do (
        setlocal enabledelayedexpansion
        set /p line=
        echo(%%a!line!>>%outfile%
        endlocal
    )
)<%f2%

pause

This code will write the merged file into mix.txt. You can adjust the target file by replacing mix.txt with any other path.

MichaelS
  • 5,941
  • 6
  • 31
  • 46