Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a text file (ip.txt) containing regex search parameters to serach for
ip and host key-value pair separated by space/tab in Windows host file. Contents
of ip.txt will be like below
ip.txt
---------
"^10.10.10.10 *abc.xyz.com"
"^20.20.20.20 *efg.xyz.com"
"^30.30.30.30 *thf.xyz.com"
-------------------------Now I have written a script which searches for those regex patterns and if not found
add the pair in hosts file and the pair it writes is written
in a report.txt file which will be used to write another batch file which will
read the entries added and delete it (just a reverse scipt)
When my script works it directly adds the regex pattern stored in %%a
to hosts file. I want to add like 10.10.10.10 abc.xyz.com instead of the pattern.My script is not working properly. Plz help
---------
@echo offset hf=%windir%\system32\drivers\etc\hosts
echo ++++++++++++++++++++++++++++++++++++++ >> report.txt
echo host entries added >> report.txt
echo ++++++++++++++++++++++++++++++++++++++ >> report.txtFOR /F "delims=^n tokens=*" %%a IN (ip.txt) DO (findstr /n /r %%a %hf%
echo %%a
echo error = %errorlevel%
IF %errorlevel% equ 1 (goto :step1) else (goto :step0)
:step1
echo %%a>>%hf%
echo %var% >> report.txt
:step0
echo found
)
echo ++++++++++++++++++++++++++++++++++++++ >> report.txtpause
arin

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |