SoFunction
Updated on 2025-04-06

Code to delete lines of specific content in HOSTS using batch processing


cd /d %windir%\system32\drivers\etc 
rem Delete first to prevent renaming failure
del  
ren hosts  
for /f "eol=# tokens=1,2" %%i in () do call :checkvalue %%i %%j 
goto end 

:checkvalue 
echo %2 | find /i "local" 
if %errorlevel%==1 (echo %1 %2 >>hosts) 

:end