Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


script to edit hosts file

Posted on 2013-01-22
Medium Priority
Last Modified: 2013-01-22
Is is possible to edit the hosts file with a script that the user can run from their machine.  One of our groups needs to remove the # symbol from one line in the hosts file.  The line is:

#         localhost

I want to get a script that the user can run that will remove the # symbol from that line.

Any help is much appreciated.
Question by:redsox01532
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 84

Expert Comment

ID: 38805295
sed -i.bak '/' hostsfile

Author Comment

ID: 38805302
how would I have the users run this from their pc's?  do I save it as a .bat file or simply run it from the command prompt?
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 38805303
make a new file with no # in it
Then copy that file remotely to all the machines in the given locations replacing the old file or rename the file first then copy
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 38805309
I thought of doing this but a some of the users are field users.  I was hoping to have them run a script from their machine that would do this for them.  Not sure if that is possible.   They need this b/c they are installing an application that needs the # removed from that line in order to work.
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 38805376
Copy the following line into .bat file then ask them to open it which will do the trick

echo " localhost" >> C:\Windows\System32\drivers\etc\hosts

Author Comment

ID: 38805412
thanks.  that added the entry but it didnt remove the # local host entry.  do i need to add something to the bat to do that as well?
LVL 19

Accepted Solution

Raheman M. Abdul earned 2000 total points
ID: 38805434
You can just ignore that because # is like comment and the dos ignores the characters whatever follows # on the line.

Author Comment

ID: 38805451
great.  Thank you.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question