Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In dos, is there a way to merge a set of files so that for instance

1.txt

a
b
c

and

2.txt

1
2
3

becomes

merged.txt

a 1
b 2
c 3

Just like the paste command on *nix systems

share|improve this question
3  
dos as in "dos - operating system" or as in "windows cmd.exe" ? – akira Jul 1 '10 at 13:26
    
cygwin works for me – XIMRX Aug 4 '14 at 9:57
up vote 1 down vote accepted

Nope, you'll need to merge the lines with a program, or a scripting language, like Python.

Update: Look at these Win ports of GNU utilities, it includes paste (.exe)

share|improve this answer
1  
Too bad. Sukcs not to have Linux at work... :p – Paul Jul 1 '10 at 13:40
    
@Paul: install cygwin.com/setup.exe – akira Jul 1 '10 at 14:21

If the data reasonably simple, you could do it with Excel. Or you could download OpenOffice and do it in Calc, but the method in Calc is a pain. (You need to paste the data into two columns then merge them with the "Concatenate" function, in formula form (e.g. concatenate(Row1; row2;))

share|improve this answer

Definitely agree that a port of Unix tools or a scripting language is the way to go (although VBScript or Powershell are probably more convenient choices than Python for Windows users), but merging two files IS possible in DOS:-

@ECHO OFF

REM .bat to merge 1.txt and 2.txt

GOTO :Main

:StartMerge
    SET /P _a=<%1
    SET /P _b=<%2

    ECHO %_a% %_b%

    DEL %1 %2

    GOTO :EndMerge

:CleanUp
    SET _LinesIn1=
    SET _LinesIn2=

    SET _a=
    SET _b=

    GOTO :EOF

:Main
    SET _LinesIn1=0
    SET _LinesIn2=0

    FOR /F "delims=: tokens=1,*" %%i IN ('findstr /n "^" 1.txt') DO (
        ECHO.%%j>_c1n%%i
        SET /A _LinesIn1+=1
    )

    FOR /F "delims=: tokens=1,*" %%i IN ('findstr /n "^" 2.txt') DO (
        ECHO.%%j>_c2n%%i
        SET /A _LinesIn2+=1
    )

    IF %_LinesIn1% NEQ %_LinesIn2% (
        ECHO Cannot merge files; mismatched line count:-
        ECHO   1.txt - %_LinesIn1% lines
        ECHO   2.txt - %_LinesIn2% lines

        DEL _c*

        GOTO :CleanUp
    )

    FOR /L %%n IN (1, 1, %_LinesIn1%) DO (
        CALL :StartMerge _c1n%%n _c2n%%n

        :EndMerge
        REM No-op to avoid ") was unexpected at this time." error
    )

    GOTO :CleanUp

File under "Just because you can, doesn't mean you should." :-)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .