Replace one word with multiple words w/ BatchSubstitute.bat?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sj10
Posts: 1
Joined: 14 Jan 2010 20:16

Replace one word with multiple words w/ BatchSubstitute.bat?

#1 Post by sj10 » 14 Jan 2010 20:38

I am trying to replace a single word in a file with multiple words (a multi-word string of text). I imagine it's easy but have not yet cracked it.

For example, replace the string "Yellow Submarine" with "Blue Submarine" in color.txt and pipe it into a new file called newfile.txt.

Below are my two attempts, and the error messages returned in each case.

(1.) I tried:
BatchSubstitute.bat "Yellow Submarine" "Blue Submarine" color.txt>newfile.txt

This was returned:
Submarine" "Blue was unexpected at this time.

(2.) I tried:
BatchSubstitute.bat "Yellow Submarine" Blue Submarine color.txt>newfile.txt

This was returned:
Submarine" Blue Submarine color.txt"=="" was unexpected at this time.

I'm not a programmer (former web developer/HTML coder actually) and I don't know VB. I would like to do this with BatchSubstitute.bat if possible.

Any help appreciated!

Steve

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2010 00:11

sj10,

There is actually a bug in the batch file. To fix this replace the IF statement in the batch script from:

if "%*"=="" findstr "^::" "%~f0"&GOTO:EOF
to:
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF

Let me know if it works for you.
Thanks.

Post Reply