一、实验要求
批处理
有两个文本如下,实际中并不知道两文本各有多少行:
文本1.txt
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ccccccccccccccccccccccccccccccccccccccc
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
ggggggggggggggggggggggggggggggggggggggg
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
文本2.txt
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
要求用Windows下批处理和Linux下的shell脚本完成,两文本交替输出:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
ccccccccccccccccccccccccccccccccccccccc
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ggggggggggggggggggggggggggggggggggggggg
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
要求:
1 尽量不生成临时文件
2 代码要高效,代码尽量简洁
3 给出各种情况的测试结果截图(正常文件,巨大文件,一个空文件,两个空文件)
二、实验过程
1、Windows下批处理,两文本交替输出
新建文件夹BAT,并在其中新建三个txt文件:
1.txt内容如下:
2.txt内容如下
2818.txt(代码内容)如下:
@echo off set "paths=1.txt" for %%a in ("%paths%") do ( if "%%~za" equ "0" ( echo "1.txt empty" ) else ( echo "1.txt not empty" ) ) set "paths=2.txt" for %%a in ("%paths%") do ( if "%%~za" equ "0" ( echo "2.txt empty" pause ) else ( echo "2.txt not empty" ) ) for /f "delims=" %%i in (1.txt) do set /a n+=1&call,set "_%%n%%=%%i" for /f "delims=" %%i in (2.txt) do set /a m+=1&call,set ".%%m%%=%%i" if %n% gtr %m% (set "num=%n%") else (set "num=%m%") for /l %%i in (1,1,%num%) do ( if defined _%%i call,echo %%_%%i%% if defined .%%i call,echo %%.%%i%% ) pause>nul
然后将2818.txt的后缀改为bat,如下图所示:
然后双击bat文件,则成功运行,如下图所示:
2、Linux下的shell脚本完成,两文本交替输出
像上面的1一样创建1.txt与2.txt,然后“vim 20212818.sh”创建代码文件,代码文件内容为:
paste 1.txt 2.txt | tr "\t" "\n"
运行截图如下: