Sign in with
Sign up | Sign in
Your question

Batch file to unite txt file row into one?

Tags:
  • Programming
  • Apps
Last response: in Apps General Discussion
Share
August 17, 2011 1:39:57 PM

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.

More about : batch file unite txt file row

a b L Programming
August 17, 2011 11:49:29 PM

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 :) 
August 18, 2011 5:16:58 AM

@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...
August 18, 2011 5:24:27 AM

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 =]
August 19, 2011 6:55:56 AM

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
a b L Programming
August 22, 2011 7:51:11 PM

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.
August 23, 2011 5:51:57 AM

yeah batch files are great to solve annoying everyday issues this batch was meant to unite reports for web site... =]


PhilFrisbie said:
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.

!