本帖最后由 aloha20200628 于 2024-1-26 12:52 编辑
给两个版本参考,用楼主提供的样本文件测试均予通过。
一。用sed.exe(从本站第三方工具可自由下载),简明利索,且不必过问文件编码问题,也许sed.exe默认继承源文件编码。 | @echo off | | for /f %%n in ('sed -n "$=" 1.txt') do set/a "n=%%n-4" | | sed "%n% r 2.txt" 1.txt>1.new.txtCOPY |
二。纯P的另一套思路。第3行获取1.txt总行数,第4行切出1.txt前段,第5行切出1.txt后段,第6行拼接各段合成结果。 | @echo off &setlocal enabledelayedexpansion | | chcp 65001>nul | | set "n=1" & for /f %%n in ('find /v /c "" ^<1.txt') do set/a "m=%%n-4" | | (for /f "delims=" %%s in (1.txt) do if !n! leq !m! (set/a "n+=1" & echo,%%s))>1.1 | | more +!m! 1.txt>1.2 | | copy /y 1.1+2.txt+1.2 1.new.txt>nul | | del /q 1.1 1.2 & chcp 936>nul & endlocal&exit/bCOPY |
|