Batch - edit specified line in text file

无人久伴 提交于 2019-11-29 16:45:27

try this:

@ECHO OFF &SETLOCAL
SET "file=file"
SET /a Line#ToSearch=2
SET "Replacement=0"

(FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
    SET "Line=%%b"
    IF %%a equ %Line#ToSearch% SET "Line=%Replacement%"
    SETLOCAL ENABLEDELAYEDEXPANSION
    ECHO(!Line!
    ENDLOCAL
))>"%file%.new"
TYPE "%file%.new"

Note: this doen't work properly for lines starting with colons :, this might be fixed if needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!