regex - Windows batch to add/replace entry in hosts file -
i read topic first step usefull begin with. can add several lines hosts file.
i trying, without success, search , replace string regular expression. exemple, if host file contains "someip website.com" modify line obtain "newip website.com".
i can find if line contains "website.com", don't know (if possible) how line , replace ip address via regular expression pattern.
%windir%\system32\find /c /i "website.com" %hostpath% >nul if %errorlevel% neq 0 echo %newline%^%server% website.com>>%hostpath%
i'm lost thank answers :)
see https://stackoverflow.com/a/16735079/891976 repl.bat dbenham supports regular expression search , replace.
type "hosts" | repl "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b website.com" "newip website.com" m >"hosts.new" move /y hosts.new hosts
repl.bat: http://www.dostips.com/forum/viewtopic.php?f=3&t=3855
Comments
Post a Comment