0

It concerns the HOSTS file, Windows 7 Ultimate 64bit. I want all entries/lines with a certain name in it to be written in a .txt file. how can I do this in the command line tool?

  • 1
    Write a batch file to read each line and if it contains your criteria write it to your text file... what have you tried so far? – Kinnectus Jun 15 '15 at 12:34
  • I haven't done anything yet. I don't know what a batch file would look like in this case. – labrat Jun 15 '15 at 13:16
  • @BigChris That's not a very efficient way to solve a problem when it can be done in one line using a single built-in command ;) – DavidPostill Jun 15 '15 at 14:05
  • Hardly fair lol... the OP didn't stipulate any preferred method or scripting language... and, as can be seen, some didn't know findstr existed, just like myself... a great solution by Lenniey, though... – Kinnectus Jun 15 '15 at 14:11
5

Well you could use findstr:

findstr "localhost" C:\Windows\System32\drivers\etc\hosts > C:\localhost_hosts.txt
  • Cool. Didn't know of this command. – LPChip Jun 15 '15 at 13:09
  • great! thx. it worked. – labrat Jun 15 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.