Computing.Net > Forums > Programming > Parse 2 files line by line to 1

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Parse 2 files line by line to 1

Reply to Message Icon

Name: t8mas
Date: April 7, 2009 at 00:47:26 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 7, 2009 at 00:57:07 Pacific
Reply:

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


0

Response Number 2
Name: Mechanix2Go
Date: April 7, 2009 at 01:28:24 Pacific
Reply:

@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


0

Response Number 3
Name: t8mas
Date: April 7, 2009 at 03:07:12 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Multiple join query MAC address of remote sys...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Parse 2 files line by line to 1

read file line by line www.computing.net/answers/programming/read-file-line-by-line/15089.html

How to compare 2 files using awk? www.computing.net/answers/programming/how-to-compare-2-files-using-awk/15598.html

awk: search string across 2 files www.computing.net/answers/programming/awk-search-string-across-2-files/10872.html