Remove Hosts file entries

I need a script to remove about 100 entries from an existing Hosts file from Windows XP PC's. The IP addresses are changing and DNS will now be provided via our Win2k3 server. I know I cannot use a wildcard in Hosts files, so what do you recommend.  We cannot replace the Hosts file because there are other entries that are not in DNS yet. Thanks for your help.
Who is Participating?
Bill BachConnect With a Mentor PresidentCommented:
There's a free tool REMFILE from this location:

This simple tool removes lines that include matching strings from a file.  A single iteration would look like this:
    REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
    COPY c:\Windows\System32\Drivers\etc\HostsNew.  C:\Windows\System32\Drivers\etc\Hosts.

Or, you could do them in pairs:
    REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
    REMFILE "second string to remove" <C:\Windows\System32\Drivers\etc\HostsNew. >c:\Windows\System32\Drivers\etc\Hosts.

You can then build a batch file with 100 lines in it to remove all the excess gunk from your HOSTS files.  

Honestly, though, I echo the sentiments of the other folks -- leave the hosts file for now and blow it away when you are done.  This works as long as they are not changing the IP addresses at the same time.
Create a host fiel with the entries you want and then replace the existing files using a loginscript? Depending on the amount of clients you have it might be worth setting up dns properly...
>> "We cannot replace the Hosts file because there are other entries that are not in DNS yet."

Are these additional entries you need the same on all machines? If so I would say to do the following:

Create a generic hosts file with all these entries and save it.

Create a script (Logon or via GPO) to copy this file over the existing one.

Why not just wait until you have all the entries in DNS and blow away the hosts files? Seems like you are going to have a lot of fun troubleshooting name resolution problems if you are relying on hosts and DNS... JMO
603currierAuthor Commented:
Thanks for the responses.  The entity forcing this change is an external one and waiting until DNS is available for all sites is not any option.
603currierAuthor Commented:
They are changing the IP address unfortunately.  Thanks you've given me good ifno.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.