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