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

delete multiple ips from hosts file

Reply to Message Icon

Original Message
Name: arin123
Date: July 2, 2008 at 03:59:07 Pacific
Subject: delete multiple ips from hosts file
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


Report Offensive Message For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: delete multiple ips from hosts file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software