Computing.Net > Forums > Disk Operating System > delete multiple ips from hosts file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

delete multiple ips from hosts file

Reply to Message Icon

Name: arin123
Date: July 2, 2008 at 03:59:07 Pacific
OS: Win XP
CPU/Ram: 2gb
Comment:

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.com

The below batch file reads ip.txt and search for it inside hosts file
and delete it from hosts

But the for loop is not working for the first entry of ip.txt but works fine for the remaining entries.

hostremove.cmd
---------------------
@echo off

FOR /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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: delete multiple ips from hosts file

deleting multiple lines in txt file www.computing.net/answers/dos/deleting-multiple-lines-in-txt-file/15605.html

deleting a character from a filenam www.computing.net/answers/dos/deleting-a-character-from-a-filenam/13164.html

read multiple variable from file to batc www.computing.net/answers/dos/read-multiple-variable-from-file-to-batc/7436.html