Skip navigation

JSI Tip 4862. ReadIn freeware allows parsing of files that contain CMD control characters.

Downloads
readin.zip


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:\folder\filename.txt /R=#') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:\folder\filename.txt file, replacing each control character with #, and then calling internal label :parse.

for /f "Tokens=*" %%a in ('ReadIn /F=C:\folder\filename.HTM /R=#*#') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:\folder\filename.htm file, replacing each control character with #*#, and then calling internal label :parse.

for /f "Tokens=*" %%a in ('ReadIn /F=C:\folder\filename.HTM /C') do set line=%%a&call :parse will set the line environment variable to the contents of each record in the c:\folder\filename.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     ¡     ¥     Þ     ¦     ü     ¼     ¾     ¢     ½     »     ¨     ©     ¬     º  
  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 off
setlocal
set SUB=ABCDEFGHIJKLMNOPQRSTUVWXYZ
if \{%2\}

\{\} goto dummy if not exist %1\*.* goto dummy set web=%1 set web=%web:"=% set report=%2 if exist %report% del /q %report% for /l %%a in (0,1,999) do call :Build %%a endlocal goto :EOF :dummy @echo Syntax: WebFolder ReportFile endlocal goto :EOF :Build set tip=%1 set /a num=%tip% set /a tip=%tip% + 10000 set tip=%tip% set fold=%tip% set tip=%tip:~1,4% if %num% EQU 278 goto :EOF if %num% EQU 896 goto :EOF set /a num=%num% + 10000 set /a num=%num% / 100 set /a num=%num% * 100 set num=%num% set num=%num:~1,4% set /a fold=%fold% set /a fold=%fold% - 10000 set /a subsubc=%fold% / 500 call set SUBC=SUB%%sub:~%subsubc%^,1%% set gettip="%web%\%SUBC%\TIP%num%\rh%tip%.htm" set out=%subc%\TIP%num%\rh%tip%.htm for /f "Tokens=*" %%i in ('ReadIn /F^=%gettip% /C') do set line=%%i&call :detail goto :EOF :detail if "%line%"

"" goto :EOF set substr=¼H3¾%tip:~1,3% ¦raquo» call set work=%%line:%substr%=%% if "%work%" EQU "%line%" goto :EOF :output @echo %out% %line%>>%report%


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish