批处理如何获取指定txt文本某几行中的内容,存入新的文本中?

2025-03-24 16:10:26
推荐回答(2个)
回答1:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%i in ('findstr /n .* a.txt') do (
set /a "n=(%%i-1)/10 + 1"
if !n!==12 set n=11
echo %%j>>!n!.txt)

回答2:

@echo off
set f=1&set n=1
FOR /F "delims=" %%a IN (a.txt) DO (set a=%%a
call :AAA
)
exit

:AAA
if %f% GTR 10 echo %a%>>%f%.txt & goto :EOF
if %n% LEQ 10 echo %a%>>%f%.txt
set /a n+=1
if %n% GTR 10 set n=1&set /a f+=1
goto :EOF