Parse 2 files line by line to 1

April 7, 2009 at 00:47:26
Specs: Windows XP
Hi,

I have this problem that i want to parse each line of file 1 and 2 and then combine it side by side on a new file. say, file 3.

example.

if i have these lines from file 1:
better
beer
and i have these lines from file 2:
honey
bees

i should have a file 3 with the following output lines:

better honey
beer bees

kindly help me. thanks.


See More: Parse 2 files line by line to 1

Report •


#1
April 7, 2009 at 00:57:07
if you have vbscript, open each file and read the lines into arrays. then use a loop to display the 2 arrays, each time printing out the contents side by side.
an alternative : If you can download coreutils ( see link in my sig), you can just do a paste
c:\> paste file1 file2
better  honey
beer    bees

Unix Win32 tools | Gawk for Windows


Report •

#2
April 7, 2009 at 01:28:24
@echo off > newfile & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in (file1) do (
set /a N+=1
set o!N!=%%a
)

set N=
for /f "tokens=* delims=" %%a in (file2) do (
set /a N+=1
set t!N!=%%a
)

for /L %%a in (1 1 !N!) do (
echo !o%%a! !t%%a! >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
April 7, 2009 at 03:07:12
wow! thanks M2. as expected from you, it works! I've read most of your codes here and thanks for replying. ghost, ill try that if i have a chance. unfortunately, all i can use is batch file/dos cmd prompt for now.thanks anyway.

Report •

Related Solutions


Ask Question