我正在使用几天前在 StackOverflow 上找到的解决方案:
@echo off
setlocal enabledelayedexpansion
REM Line number of the delimiter line:
for /F "delims=:" %%a in ('findstr /N "^xxyyzz" "Input.bin"') do set "lines=%%a"
echo %lines%
REM Extract the part of the Input.bin following the delimiter line:
< "Input.bin" (
REM Pass thru the first lines:
for /L %%i in (1,1,%lines%) do set /P "="
REM Copy the rest to output bin:
findstr "^"
) > Output.bin
一切正常,但对于某些文件,我收到错误消息“队伍……太长了”。我知道这个问题与管道。我还发现了提示:
“仅当 FINDSTR 通过重定向或管道读取输入时才会发生行太长错误。如果将文件的名称(路径)直接传递给 FINDSTR,该错误就会消失。“
我的脚本应该如何调整(根据上述提示)来克服这个问题?