0
我有一個txt文件。我只想刪除第4行和第5行。使用批處理刪除文本文件中的某一行
以前
Line1
Line2
Line3
Line4 (need to delete)
Line5 (need to delete)
Line6
後
Line1
Line2
Line3
Line6
我有一個txt文件。我只想刪除第4行和第5行。使用批處理刪除文本文件中的某一行
以前
Line1
Line2
Line3
Line4 (need to delete)
Line5 (need to delete)
Line6
後
Line1
Line2
Line3
Line6
嘗試下面的代碼,會做的正是你需要什麼:
@echo off
cls
setlocal EnableDelayedExpansion
set /a count=0
if exist neww.txt (del /s /q neww.txt)
for /f "tokens=*" %%a in (onee.txt) do (
set /a count+=1
if !count! EQU 4 (
echo do nothing
)else if !count! EQU 5 (
echo do nothing
)else (
echo %%a>>neww.txt
)
)
move /y neww.txt onee.txt
@echo off
setlocal EnableDelayedExpansion
call :CopyLines <input.txt> output.txt
move /Y output.txt input.txt
goto :EOF
:CopyLines
rem Copy lines 1, 2 and 3
for /L %%i in (1,1,3) do (
set "line="
set /P "line="
echo(!line!
)
rem Omit lines 4 and 5
for /L %%i in (4,1,5) do set /P "line="
rem Copy the rest
findstr "^"
exit /B
^h你選擇第4行還是第5行?按內容還是按位置? – Magoo