Batch: Search for string to skip lines above and write results to new file

痴心易碎 提交于 2019-12-01 09:11:30

You got two main problems, a FOR /F can't read empty lines (as you discover) and if you use delayed expansion you got trouble with exclamation marks and carets in the line set read-input=%%i.

You can solve both, the empty lines with prefixing each line with a line number by using findstr. The second with the delayed toggling technic.

SETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ t.txt"`) do (
    set "var=%%a"
    SETLOCAL EnableDelayedExpansion
    set "var=!var:*:=!" This removes the prefix
    echo(!var!
    ENDLOCAL
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!