Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have some ip/host pair in a text file ip.txt
ip.txt
-------
10.10.10.10 xxx.abc.com
20.20.20.20 yyy.abc.comThe below batch file reads ip.txt and search for it inside hosts file
and delete it from hostsBut the for loop is not working for the first entry of ip.txt but works fine for the remaining entries.
hostremove.cmd
---------------------
@echo offFOR /F "delims=^n tokens=*" %%a IN (ip.txt) do call :func "%%a"
goto :eof
:func
set line=%1
set hf=%windir%\system32\drivers\etc\hosts
find /v %line% < %hf% >> newhosts
rename newhosts hosts
copy /a /y hosts %hf%
del hosts:eof
pause
echo on
------------------------
Please help.arin

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |