Use batch to delete lines of specific content in hosts


Q: Use bat batch to delete or modify the entries specified in hosts, for example, for   Localhosts, can you delete or change all the records with local in hosts?


Copy codeThe code is as follows:
cd /d %windir%\system32\drivers\etc 
rem   Delete hosts.bak first to prevent renaming failure  
del hosts.bak 
ren hosts hosts.bak 
for /f “eol=# tokens=1,2” %%i in (hosts.bak) do call :checkvalue %%i %%j 
goto end 

echo %2 | find /i “local” 
if %errorlevel%==1 (echo %1 %2 >>hosts)