How can I delete (remove) lines from the hosts files with batch file? Hello all, I wonder if my question is right place or wrong place. My question is that Is there anyway to delete (remove) two specific lines from the hosts file with a batch file like this one that I add lines below ? Thank you in advance. Here's the one I add
Not very professional, but works for few lines Code: findstr /i /v /c:"127.0.0.1 facebook.com" %WINDIR%\system32\drivers\etc\hosts | findstr /i /v /c:"127.0.0.1 youtube.com" > %WINDIR%\system32\drivers\etc\hosts.tmp del %WINDIR%\system32\drivers\etc\hosts ren %WINDIR%\system32\drivers\etc\hosts.tmp hosts
@abbodi1406, Thank you so much for your help. One more question please. If I need to remove two more lines from hosts file (totally 4 lines), Can you show me how to do that please.
@abbodi1406, I just saved it as .bat and run it as admin. Unfortunately, it does not remove two specific lines " facebook & youtube" and a "hosts.tmp" file was saved . Please check your command lines. Thank you again.
@abbodi1406, It does not work. Can you check again please. " 127.0.0.1 facebook.com & 127.0.0.1 youtube.com " can not be removed from hosts file. Thanks for your help and Have a great day.