Adding a sentence to host file.

Posted on 2006-11-10
Last Modified: 2010-04-16
Hello All, i wish to know how to add a sentence to host file using the batch file.

echo localhost >> "%systemroot%\system32\drivers\etc\hosts"

But everytime i double click this batch file. Instead of going to the next sentence of the host file, it will just add next to the last line of the host file. example:-

xx.xx.xx.xx After i double click the host file above it will become:-

xx.xx.xx.xx localhost

But i want the localhost to be at the next sentence. Isst possible?

Please advice me.

Question by:YeoBoonWah
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
  • 2
  • 2
LVL 84

Accepted Solution

ozo earned 43 total points
ID: 17912889
echo >>  "%systemroot%\system32\drivers\etc\hosts"
echo localhost >> "%systemroot%\system32\drivers\etc\hosts"
LVL 19

Assisted Solution

by:Albert Van Halen
Albert Van Halen earned 41 total points
ID: 17912900
You can use \n characters

IE echo "\n127.0.0.1 localhost" >> "%systemroot%\system32\drivers\etc\hosts"
LVL 84

Expert Comment

ID: 17913009
if this is dos, you may need
echo. >>  "%systemroot%\system32\drivers\etc\hosts"

Assisted Solution

JRockSolid earned 41 total points
ID: 17921353
Make sure your cursor i on an empty line in your host file then save it  EXAMPLE

1 localhost
2 localhost
3 localhost
4 localhost
5 localhost
6  |<<<<Cursor here and save
now try it

Expert Comment

ID: 17958477
Any Luck YEO?

Featured Post

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!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

734 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