can any one, help me to detect any statements which are not having #, ie. non commented statements from hosts file (/system32/drivers/etc/hosts) using windows batch commands ?
For example : ip address specified in that file which will not have #
这对我有用:
findstr "^[^#]*[0-9a-f][.:][0-9a-f]" c:\windows\system32\drivers\etc\hosts
这将找到非注释行
find /v "#" < hosts
Not completly sure this does not leave something without filtering. But
findstr /R /c:"^[^#]*[0-9a-f:.]" %systemroot%\system32\drivers\etc\hosts
It will incorrectly? detect lines that contains invalid formated ip address resolutions (ej: an ip address and no name) But should remove any commented/not active lines.
This code just show lines that don't have a # in first column, hope this helps:
setlocal EnableDelayedExpansion
for /f "delims=¶ tokens=*" %%A in ('"type %SystemRoot%\System32\drivers\etc\hosts"') do (
set var=%%A
if NOT "!var:~0,1!" == "#" (echo !var!)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.