Computing.Net > Forums > Windows XP > Batch file to remove strings

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.

Batch file to remove strings

Reply to Message Icon

Name: Blindness
Date: December 9, 2008 at 12:20:03 Pacific
OS: na
CPU/Ram: na
Product: N/a / NA
Comment:

Hello,

I'm not sure this is the right section, because I need this script to work on XP, but batch programing is somewhat more DOS realted.

So I'm looking for a batch script which deletes certain lines from a file. To be exact:
I made a file which add 2 new lines to /windows/system32/drivers/etc/hosts.
An example:
1.2.3.4 www.asite.com
1.2.3.4 www.anothersite.com

Let's say this is the "installer" of something. Now I also need an "uninstaller", which remove these lines. My first idea was to make a backup of the file and then restore it at the uninstall but other lines, added later would also lost.

Thank you in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 10, 2008 at 07:44:53 Pacific
Reply:

If there are just 2 lines of interest and you have them in a text file named added, try this script below. You could extend it some but if there were a whole slew of lines it would get unweildy.

========= remove2.bat
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (added) do (
set /a N+=1
set v!N!=%%a
)

find /v "!v1!" < hosts | find /v "!v2!" > hosts.new


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Blindness
Date: December 11, 2008 at 13:54:58 Pacific
Reply:

Thank you, will try it soon!


0

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 Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file to remove strings

Batch file to delete by date www.computing.net/answers/windows-xp/batch-file-to-delete-by-date-/135330.html

Batch file to stop users using ... www.computing.net/answers/windows-xp/batch-file-to-stop-users-using-/152561.html

Using BATCH file to backup data www.computing.net/answers/windows-xp/using-batch-file-to-backup-data/66927.html