• 批处理


    有两个文本如下,实际中并不知道两文本各有多少行:

    文本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 给出各种情况的测试结果截图(正常文件,巨大文件,一个空文件,两个空文件)
    windows 下的代码为

    @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
    



    Linux下的代码为

    paste txt1.txt txt2.txt | tr " " " "

  • 相关阅读:
    <Android HAL 之路> HAL 简介
    <Android 应用 之路> 简易贪吃蛇
    略论研发评审的必要性
    微信支付开发(7) 收货地址共享接口V2
    连接点和线路点的区别
    IP地址分类及子网掩码详解
    基于UDP协议的多路广播地址
    频分双工
    航空连接器、端子
    表面粗糙度及加工符号
  • 原文地址:https://www.cnblogs.com/besti-20199303/p/11847711.html
Copyright © 2020-2023  润新知