Click to See Complete Forum and Search --> : Search and replace in a batch file


SteveTaylor
February 8th, 2007, 05:46 AM
Hello all,

I am writing a batch file in DOS, one of its functions is to search through a file for a string of the format:

SOME TEXT WHICH MUST NOT CHANGE Version1.2 MORE CONSTANT TEXT

and replace it with:

SOME TEXT WHICH MUST NOT CHANGE Version1.3 MORE CONSTANT TEXT
or
SOME TEXT WHICH MUST NOT CHANGE Version 2 MORE CONSTANT TEXT

Depending on the values read from a different file.

I have found the function FIND which will find the entire line but I am not sure how to extract the Version and number and replace it.

FINDSTR also seems to almost do what I need but I having trouble making the final step and I cannot find any example which already have this done.

Can anyone help?

PeejAvery
February 8th, 2007, 07:45 PM
Take a look at this (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx?mfr=true) Microsoft documentation. It should answer your questions.

SteveTaylor
February 9th, 2007, 04:48 AM
Thanks for the link.

I do not know if I am being blind but I cannot find information on how to do a string replace on there?

PeejAvery
February 9th, 2007, 09:18 AM
Well, findstr does exactly as its name says. What you need is to do regular expressions. Regular expressions cannot be done in DOS.