Solved Appending lines from tow files

November 11, 2011 at 21:41:47
Specs: Windows XP
the first file contains several lines the 2nd file contains same numbers of lines
I want to append the line no 1 (in the second file) to the line no 1 in the first file and line no 2 (in the second file) to the line no 2 in the first file and so on ie each line in the 2nd file to its matching number in the 1st file
the length of the line may be one word or a long sentence

thanks in advance for any help


See More: Appending lines from tow files

Report •


#1
November 12, 2011 at 09:04:40
Need to create two new files 1and2 and 2and1.

Report •

#2
November 12, 2011 at 19:22:55
✔ Best Answer
Please test this script. Am not sure how many lines can be concatenated. Unfortunately blank lines will be omitted from the output. Characters with special meaning in the Command Shell may not be handled.

Good luck.

@echo off>%temp%\out.txt
cls
setlocal enabledelayedexpansion

set cnt=1
for /f "tokens=*" %%1 in ('type file1.txt') do (
    set a!cnt!=%%1
    set /a cnt+=1
)

set cnt=1
for /f "tokens=*" %%1 in ('type file2.txt') do (
    set b!cnt!=%%1

    call echo %%a!cnt!%% %%b!cnt!%%>>%temp%\out.txt
    set /a cnt+=1
    )

more %temp%\out.txt


Please come back & tell us if your problem is resolved.


Report •

#3
November 12, 2011 at 23:45:11
Hi wahine worked like charm
you are the person I reckoned with
healthy mind in healthy body in kind and generous person

thank you very very very much

also I should thank wizard-fred for his response


Report •

Related Solutions


Ask Question