0

I have a txt file . I want to delete line 4 and line 5 only.

Before

Line1  
Line2  
Line3  
Line4 (need to delete)  
Line5 (need to delete)  
Line6  

After

Line1  
Line2  
Line3  
Line6
1
  • 1
    How do you select lines 4 and 5? By content or by position? Commented Nov 10, 2015 at 5:36

2 Answers 2

1
@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
Sign up to request clarification or add additional context in comments.

Comments

0

Try below code which would do exactly what you require :

@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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.