If a file that you want to parse has command control characters, like an HTML file, the CMD.EXE processor will treat these characters as controls, causing your script to malfunction.

The ! % ^ & | " characters have special meaning to the CMD.EXE processor, as well as the = ; ( ) , : ' characters, when used in various combinations.

Your script is also NOT able to detect TAB characters.

I have scripted CMDCTRL.bat, CMDCTRLdo.vbs, and CMDCTRLundo.vbs to allow a batch job to process a file that contains command control characters, by creating a new file in which the command control characters have been replaced, using the following table.

  Control Character   !     %     ^     &     |          >     "     =     ;     (     )     ,     :     '     TAB  
  Resulting Character     ¡     ¥     Þ     ¦     ü     ¼     ¾     ¢     ½     »     ¨     ©     ¬     º     ±     «  
  Keystrokes
  (Numeric Keypad)
  ALT+
  0161     0165     0222     0166     0252     0188     0190     0162     0189     0187     0168     0169     0172     0186     0177     0171  

The syntax for using CMDCTRL.bat is:

CALL CMDCTRL iFile oFile \[/U\]

Where:

<b>iFile</b> is the fully qualified file name of the input file that contains the command <b>Control Character</b>s.

<b>oFile</b> is the fully qualified file name of the output file that will <b>Resulting Character</b>s

<b>/U</b>    is an optional switch that will reverse the operation, converting an <b>iFile</b> that contains
      <b>Resulting Character</b>s  to an <b>oFile</b> that contains command <b>Control Character</b>s.
NOTE: CMDCTRL.bat, CMDCTRLdo.vbs, and CMDCTRLundo.vbs must all be located in the same folder.

NOTE: For an alternate method, see How can a batch job process files that contain command control and TAB characters?

CMDCTRL.bat contains:

@echo off
setlocal
if \{%2\}<h1><a name="_goto_err1_if_not_exist_1_goto_err2_if_exist_2_del_q_f_2_set_iFile_1_set_oFile_2_if_i_ifile_EQU_ofile_goto_err3_if_3_">\{\} goto err1
if not exist %1 goto err2
if exist %2 del /q /f %2
set iFile=%1
set oFile=%2
if /i %ifile% EQU %ofile% goto err3
if \{%3\}</a></h1>\{\} goto doit
if /i \{%3\}==\{/U\} goto undoit
:err1
@echo Syntax: CMDCTRL iFile oFile /U
endlocal
goto :EOF
:err2
@echo CMDCTRL - %1 NOT found.
endlocal
goto :EOF
:err3
@echo CMDCTRL - %1 is the same file as %2.
endlocal
goto :EOF
:doit
set vbs="%~DP0CMDCTRLdo.vbs"
cscript //nologo %vbs% %iFile% %oFile%
endlocal
goto :EOF
:undoit
set vbs="%~DP0CMDCTRLundo.vbs"
cscript //nologo %vbs% %iFile% %oFile%
endlocal

CMDCTRLdo.vbs contains:

dim fso, iFile, oFile,rFile, wFile
dim iString, oString
Dim objArguments
Set objArguments = Wscript.Arguments
iFile=objArguments(0)
oFile=objArguments(1)
set fso = CreateObject("Scripting.FileSystemObject")
set rfile = fso.OpenTextFile(iFile, 1, false)
set wFile = fso.CreateTextFile(oFile, 2)
Do until rFile.AtEndOfStream = True
 iString = rFile.ReadLine
 oString = Replace(iString, "!", "¡")
 oString = Replace(oString, "%", "¥")
 oString = Replace(oString, "^", "Þ")
 oString = Replace(oString, "&", "¦")
 oString = Replace(oString, "|", "ü")
 oString = Replace(oString, "", "¾")
 oString = Replace(oString, <div class="Contentquote"><center>", "¢")
 oString = Replace(oString, "=", "½")
 oString = Replace(oString, ";", "»")
 oString = Replace(oString, "(", "¨")
 oString = Replace(oString, ")", "©")
 oString = Replace(oString, ",", "¬")
 oString = Replace(oString, ":", "º")
 oString = Replace(oString, "'", "±")
 oString = Replace(oString, vbtab, "«")
 wFile.writeLine oString
loop
rFile.close
wFile.close

<h3>CMDCTRLundo.vbs contains:</h3>
<pre>
dim fso, iFile, oFile,rFile, wFile
dim iString, oString
Dim objArguments
Set objArguments = Wscript.Arguments
iFile=objArguments(0)
oFile=objArguments(1)
set fso = CreateObject("Scripting.FileSystemObject")
set rfile = fso.OpenTextFile(iFile, 1, false)
set wFile = fso.CreateTextFile(oFile, 2)
Do until rFile.AtEndOfStream = True
 iString = rFile.ReadLine
 oString = Replace(iString, "¡", "!")
 oString = Replace(oString, "¥", "%")
 oString = Replace(oString, "Þ", "^")
 oString = Replace(oString, "¦", "&")
 oString = Replace(oString, "ü", "|")
 oString = Replace(oString, "¼", "")
 oString = Replace(oString, "¢",
") oString = Replace(oString, "½", "=") oString = Replace(oString, "»", ";") oString = Replace(oString, "¨", "(") oString = Replace(oString, "©", ")") oString = Replace(oString, "¬", ",") oString = Replace(oString, "º", ":") oString = Replace(oString, "±", "'") oString = Replace(oString, "«", vbtab) wFile.writeLine oString loop rFile.close wFile.close