Computing.Net > Forums > Disk Operating System > add/delete hosts entry using regex

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

add/delete hosts entry using regex

Reply to Message Icon

Name: arin123
Date: June 30, 2008 at 23:50:05 Pacific
OS: Win XP/SP2
CPU/Ram: 2 gb
Comment:

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 off

set hf=%windir%\system32\drivers\etc\hosts

echo ++++++++++++++++++++++++++++++++++++++ >> report.txt
echo host entries added >> report.txt
echo ++++++++++++++++++++++++++++++++++++++ >> report.txt

FOR /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.txt

pause

arin



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: add/delete hosts entry using regex

Problem creating a batc h file... www.computing.net/answers/dos/problem-creating-a-batc-h-file/14858.html

Deleting Random Reg Entries www.computing.net/answers/dos/deleting-random-reg-entries/14003.html

Help deleting old files using Windows XP www.computing.net/answers/dos/help-deleting-old-files-using-windows-xp/9395.html