Answer the question
In order to leave comments, you need to log in
How to delete lines using bat?
Hello. There is a hosts file. I need to delete 1, 2, 3, 4, 5, 6 lines from it, and then write lines with my own text instead. Help me please. How can I do that?
Answer the question
In order to leave comments, you need to log in
In general, it is better to delete not 1,2,3 ... lines, but using a type filter as in the sed post above, only using the standard findstr utility. If you give an example of the contents of the lines that need to be deleted, I will help write a filter.
If you still insist on 1,2,3, .... then you organize a loop where you read the file line by line, counting the lines and start writing from the desired line:
@echo off
setlocal enabledelayedexpansion
set "c=0"
del /f/q hosts1
for /f "tokens=* delims=" %%a in (hosts) do (
set /a "c+=1"
if !c! gtr 7 >>hosts1 echo.%%a
)
del /f/q host
copy add.txt+hosts1 hosts
del /f/q host1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question