text merge

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
krunoo
Posts: 10
Joined: 21 Nov 2012 08:15

text merge

#1 Post by krunoo » 10 Jun 2013 08:46

Hello,

cant someone help me.

I have to txt file with text. something like this:

1.txt
1
2
3
4

2.txt
a
b
c
d

and I need to get this:

output.txt
1 a
2 b
3 c
4 d

Is there a way to get this with .bat script?

Thanks everyone,
Kruno

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: text merge

#2 Post by foxidrive » 10 Jun 2013 09:01

file1.txt and file2.txt are the input files.

Code: Select all

@echo off
setlocal DisableDelayedExpansion
< file2.txt (
   for /F "delims=" %%a in (file1.txt) do (
      set file2Line=
      set /P file2Line=
      set "file1Line=%%a"
      setlocal EnableDelayedExpansion   
      echo(!file1Line! !file2Line!
      endlocal
   )
) >output.txt
pause

krunoo
Posts: 10
Joined: 21 Nov 2012 08:15

Re: text merge

#3 Post by krunoo » 10 Jun 2013 09:09

perfect.

Thank youuu!!!!

Post Reply