批处理生成文件,从不同的文本读取,但是行数相同的字符串,按顺序写入另一文本。

2025-03-04 15:58:28
推荐回答(1个)
回答1:

我做的东西需要你稍微配合一下我的要求。

弄的好乱,技术有限,没办法,要求如下。

1。代码要与他所在行号对应。如图

2。  1.txt .... 4.txt 4个文本 第1行必须空出来。


好了  按照你的要求。代码如下

@echo off

setlocal enabledelayedexpansion

::生成文本的名头

set t0a=生成文本

::确认文本行数,以1.txt为准

set n0a=-1

set n0b=0

for /f "delims=" %%i in ('type "1.txt"') do (

set /a n0a+=1)

echo 设置行数%n0a%

pause

:tt

  set /a n0b+=1

  cls

  echo 正在生成第%n0b%个文本...

  for /f "skip=%n0b% delims=" %%i in ('type "1.txt"') do (

    set t1a=%%i

    goto :z1)

  :z1

  for /f "skip=%n0b% delims=" %%i in ('type "2.txt"') do (

    set t1b=%%i

    goto :z2)

  :z2

  for /f "skip=%n0b% delims=" %%i in ('type "3.txt"') do (

    set t1c=%%i

    goto :z3)

  :z3

  for /f "skip=%n0b% delims=" %%i in ('type "4.txt"') do (

    set t1d=%%i

    goto :z4)

  :z4

  cd.>%t0a%%n0b%.txt

  echo [SPAWNCLASS]>>%t0a%%n0b%.txt

for /f "skip=72 delims=" %%i in ('findstr /n .* %0') do (

       set "var=%%i%t1a%"

       set var=!var:*:=!

       (echo.!var!)>>%t0a%%n0b%.txt

goto :z5)

:z5

  echo [OBJECT]>>%t0a%%n0b%.txt

for /f "skip=73 delims=" %%i in ('findstr /n .* %0') do (

       set "var=%%i%t1b%"

       set var=!var:*:=!

       (echo.!var!)>>%t0a%%n0b%.txt

goto :z6)

:z6

  echo [/OBJECT]>>%t0a%%n0b%.txt

  echo [OBJECT]>>%t0a%%n0b%.txt

for /f "skip=73 delims=" %%i in ('findstr /n .* %0') do (

       set "var=%%i%t1c%"

       set var=!var:*:=!

       (echo.!var!)>>%t0a%%n0b%.txt

goto :z7)

:z7

  echo [/OBJECT]>>%t0a%%n0b%.txt

  echo [OBJECT]>>%t0a%%n0b%.txt

for /f "skip=73 delims=" %%i in ('findstr /n .* %0') do (

       set "var=%%i%t1d%"

       set var=!var:*:=!

       (echo.!var!)>>%t0a%%n0b%.txt

goto :z8)

:z8

  echo [/OBJECT]>>%t0a%%n0b%.txt

  echo [/SPAWNCLASS]>>%t0a%%n0b%.txt

  if %n0b% leq %n0a% (goto :tt)

pause

exit

NAME:

UNITTYPE: