JSI Tip 4862. ReadIn freeware allows parsing of files that contain CMD control characters.
February 19, 2002
If a file that you want to parse has CMD control characters, like an HTML file, the CMD processor will treat these characters as controls, causing your script to malfunction.
The !%^&|" characters have special meaning to the CMD processor, as well as the =;(),: characters, when used in various combinations.
I asked Harry Bates, author of TECHOPS, to create ReadIn.exe, which allows the parsing of files that contain CMD control characters.
When you type ReadIn /?, you receive:
NOTE: The /C switch is mutually exclusive with the /S and /R= switches. If both /R=[x] and /C switches are specified, /C will be used.
NOTE: Application of the /S switch is performed early, so column positions will change.
NOTE: Using more than one replacement character with the /R= switch, like /R=##, will change column positions.
EXAMPLES OF USAGE
for /f "Tokens=*" %%a in ('ReadIn /F=filename.htm') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the filename.htm file (in the current folder), replacing each control character with spaces, and then calling internal label :parse.
NOTE: If you ECHO the %line% environment variable, remember that leading and trailing spaces will be dropped.
for /f "Tokens=*" %%a in ('ReadIn /F=C:folderfilename.txt /R=#') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:folderfilename.txt file, replacing each control character with #, and then calling internal label :parse.
for /f "Tokens=*" %%a in ('ReadIn /F=C:folderfilename.HTM /R=#*#') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:folderfilename.htm file, replacing each control character with #*#, and then calling internal label :parse.
for /f "Tokens=*" %%a in ('ReadIn /F=C:folderfilename.HTM /C') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:folderfilename.htm file, replacing each control character with a corresponding character, by adding 128 to the numeric value of the character, and then calling internal label :parse.
NOTE: Adding 128 to the numeric value of the character is the same as logically ORing it with X'80'.
NOTE: If you pipe the results to a file, you can use the /A and /O to copy the piped file, removing the conversion.
When using the /C switch, the resulting characters are:
Control Character | ! | % | ^ | & | | | > | " | = | ; | ( | ) | , | : | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Resulting Character | ¡ | ¥ | Þ | ¦ | ü | ¼ | ¾ | ¢ | ½ | /b> | ¨ | © | ¬ | º |
Keystrokes (Numeric Keypad) ALT+ | 0161 | 0165 | 0222 | 0166 | 0252 | 0188 | 0190 | 0162 | 0189 | 0187 | 0168 | 0169 | 0172 | 0186 |
Some of the earlier tips on this site had 3 digit tip numbers:
0004 Bypassing the WinNT logon prompt.
used to be (prior to 19-Feb-2002):
004 Bypassing the WinNT logon prompt.
I used the following code to identify the tips that needed fixing:
@echo offsetlocalset SUB=ABCDEFGHIJKLMNOPQRSTUVWXYZif {%2}
{} goto dummy if not exist %1*.* goto dummyset web=%1set web=%web:"=%set report=%2if exist %report% del /q %report%for /l %%a in (0,1,999) do call :Build %%aendlocalgoto :EOF:dummy@echo Syntax: WebFolder ReportFileendlocalgoto :EOF:Buildset tip=%1set /a num=%tip%set /a tip=%tip% + 10000set tip=%tip%set fold=%tip%set tip=%tip:~1,4%if %num% EQU 278 goto :EOFif %num% EQU 896 goto :EOFset /a num=%num% + 10000set /a num=%num% / 100set /a num=%num% * 100set num=%num%set num=%num:~1,4%set /a fold=%fold%set /a fold=%fold% - 10000set /a subsubc=%fold% / 500call set SUBC=SUB%%sub:~%subsubc%^,1%%set gettip="%web%%SUBC%TIP%num%rh%tip%.htm"set out=%subc%TIP%num%rh%tip%.htmfor /f "Tokens=*" %%i in ('ReadIn /F^=%gettip% /C') do set line=%%i&call :detailgoto :EOF:detailif "%line%"
"" goto :EOFset substr=¼H3¾%tip:~1,3% ¦raquocall set work=%%line:%substr%=%%if "%work%" EQU "%line%" goto :EOF:output@echo %out% %line%>>%report%
About the Author
You May Also Like