How to delete a line of a text file, given the line number using batch (.bat) script?

前端 未结 2 586
温柔的废话
温柔的废话 2021-01-03 15:07

I want to write a batch script where the user can enter the line number and the script will delete that line of a text file.

Eg: tmp.txt

1. aaa
2. bb         


        
2条回答
  •  渐次进展
    2021-01-03 15:44

    try out this:

    @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%"
    

提交回复
热议问题