how can I extract entries out of the HOSTS file with the command line tool in Windows 7?

0

1

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?

labrat

Posted 2015-06-15T12:29:53.953

Reputation: 117

1Write 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 – 2015-06-15T12:34:12.760

I haven't done anything yet. I don't know what a batch file would look like in this case. – labrat – 2015-06-15T13:16:44.903

@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 – 2015-06-15T14:05:42.770

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 – 2015-06-15T14:11:47.467

Answers

5

Well you could use findstr:

findstr "localhost" C:\Windows\System32\drivers\etc\hosts > C:\localhost_hosts.txt

Lenniey

Posted 2015-06-15T12:29:53.953

Reputation: 615

Cool. Didn't know of this command. – LPChip – 2015-06-15T13:09:28.313

great! thx. it worked. – labrat – 2015-06-15T13:25:59.950