如何实现多个文件的同一行同一列相加?谢谢!
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off&Setlocal EnableDelayedExpansion
set maxcols=1
set maxline=1
copy nul 3.txt >nul
call :context 1.txt
call :context 2.txt
call :result 1.txt 2.txt
start notepad.exe 3.txt
pause&goto :eof
:context
set flag=%1
set line=1
for /f "delims=" %%a in (%flag%) do (
set cols=1
for %%b in (%%a) do (
set %flag%!line!!cols!=%%b
set /a cols+=1
if !maxcols! leq !cols! set /a maxcols=!cols!
)
set /a line+=1
if !maxline! leq !line! set /a maxline=!line!
)
for /l %%z in (1,1,%maxline%) do (
for /l %%y in (1,1,%maxcols%) do (
set/p=!%flag%%%z%%y! <nul
)
echo\
)
goto :eof
:result
for /l %%z in (1,1,%maxline%) do (
for /l %%y in (1,1,%maxcols%) do (
if defined %1%%z%%y if defined %2%%z%%y (set /a _%%z%%y=!%1%%z%%y!+!%2%%z%%y!)
set/p=!_%%z%%y! <nul
>>3.txt set/p=!_%%z%%y! <nul
)
echo\>>3.txt
echo\
)
1 2 3 4
456 153 6548 315
5648 2489 321 43534
54668 3289 328 343
115 316 358 345
2315 54 654 6548
1981898 231984
212 654 6548 315 6483
212 564 5684 984 32
116 318 361 349
2771 207 7202 6863
1987546 234473
54880 3943 6876 658