且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

给定行号,使用批处理(.bat)脚本,如何删除文本文件的行?

更新时间:2023-12-05 20:44:10

尝试一下:

@echo off & setlocal 
set "InFile=Z:\Text.txt" 
set "OutFile=Z:\Erg.txt" 
set /p LineToDelete=

if exist "%OutFile%" del "%OutFile%" 
for /f "tokens=1* delims=:" %%i in ('findstr /n $ "%InFile%"^|findstr /b "%LineToDelete%:"') do findstr /v /b /c:"%%j" "%InFile%">>"%OutFile%"