Batch file to unite txt file row into one?

ralfs_k

Distinguished
Jan 20, 2011
5
0
18,510
Hi.

Can someone give me any idea how to create batch file to unite txt file rows?

txt1:

big
small
large

txt2:

apple
cookie
mouse

txt3:

big apple
small cookie
large mouse

txt1 and txt2 contains exactly the same amount of rows.

tnx.
 

PhilFrisbie

Distinguished
Yes, school is back in session. . .

If you want help you must first try, then tell what you tried and how it failed. But don't be surprised if we just provide hints so that you will earn your grade :)
 

ralfs_k

Distinguished
Jan 20, 2011
5
0
18,510
@echo off
setlocal enabledelayedexpansion
set filecontent=
for /f "delims=" %%a in (1.txt) do (
set currentline1=%%a
)
for /f "delims=" %%a in (2.txt) do (
set currentline2=%%a
set filecontent=!currentline1!!currentline2!
)
echo %filecontent% >> 3.txt



ok I tried! =] but this only concentenates last lines of txt files...
 

ralfs_k

Distinguished
Jan 20, 2011
5
0
18,510
another version this unites all text lines from 1.txt and 2.txt in one large line:

@echo off
setlocal enabledelayedexpansion
set filecontent=
set filecontent2=
for /f "delims=" %%a in (1.txt) do (
set currentline=%%a
set filecontent=!filecontent!!currentline!
)
for /f "delims=" %%a in (2.txt) do (
set currentline2=%%a
set filecontent2=!filecontent2!!currentline2!
)
echo %filecontent%%filecontent2% >> 3.txt



i'ts not like i'm not trying Phil! posting in forum is last resort after googling and trying myself to create batch file =]
 

ralfs_k

Distinguished
Jan 20, 2011
5
0
18,510
Thanks PhilFrisbie all talk no help! =[

this did the trick:

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

PhilFrisbie

Distinguished
Hey, I am sorry I did not get right back, but some of us take breaks from the 'net for family trips! ;)

But I am glad you figured out your assignment. Batch files can be a very handy tool in real life work.
 

ralfs_k

Distinguished
Jan 20, 2011
5
0
18,510
yeah batch files are great to solve annoying everyday issues this batch was meant to unite reports for web site... =]