home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / mir / 15pattrn < prev    next >
Text File  |  1992-06-29  |  33KB  |  824 lines

  1.               ═══════════════════════════════════════
  2.  
  3.                   5.   PATTERNS IN BYTE SEQUENCES
  4.  
  5.               ═══════════════════════════════════════
  6.  
  7.  
  8.             Topic 4 showed how byte distributions help us to
  9. analyze the content of a file.  One simple fact may be obscured by
  10. the length of Topic 4... that a byte survey and analysis take very
  11. little time.  The survey itself might require one to four seconds. 
  12. Reviewing it might involve another thirty seconds.
  13.  
  14.             In Topic 5 we consider sequences of bytes.  We want to
  15. identify patterns related to our objectives of:
  16.  
  17.         »    extracting searchable content;
  18.         »    recognizing record separations;
  19.         »    recognizing field separations; and
  20.         »    recognizing formatting aids.
  21.  
  22.  
  23.         ═══════════════════════════════════════
  24. 5.1           Heads and tails...
  25.               first impressions of a file
  26.         ═══════════════════════════════════════
  27.  
  28. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  29. Usage   head  file_name [ line_count ] [/a][/t] > text
  30.  
  31.         Displays in printable format the first line_count lines
  32.         within a file; the default is 10 lines.  This clone of
  33.         the Unix HEAD and TAIL utilities provides a quick check on
  34.         the likely contents of a file.  If the "/a" option is used,
  35.         accented characters are treated as printable text.  If
  36.         "/t" is specified, the display is of the TAIL of the
  37.         file, the LAST line_count lines.
  38.  
  39. input:  Normally an ASCII text file.
  40.  
  41. output: The specified number of lines is either displayed on the
  42.         screen or sent to a file.  Each non-printable character is
  43.         replaced by an ^ symbol.  If any line length exceeds 120
  44.         characters, a warning is issued.  If any line length
  45.         exceeds 1024 or the file includes null bytes, the program
  46.         advises that the target file is not ASCII text.
  47.  
  48. writeup: MIR TUTORIAL ONE, topic 5
  49. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  50.  
  51.             The HEAD program can be used to get a first impression
  52. of the beginning and of the end of most files, although it is best
  53. for ASCII text.  Try for example:
  54.  
  55.                 HEAD SVP_TXT
  56.  
  57. The result shows directly on the screen.  Alternately it may be
  58. redirected into a new file.  With the command "HEAD SVP_TXT", ten
  59. lines are shown.  Next try
  60.  
  61.                 HEAD SVP_TXT 4
  62. and then
  63.                 HEAD SVP_TXT 20
  64.  
  65. You are shown 4 lines and the next time 20 lines of text.  For line
  66. counts greater than 23, be ready to use CTL-S to stop and restart
  67. movement across the screen.
  68.  
  69.             Adding the argument "/t" switches heads to tails.
  70.  
  71.                 HEAD SVP_TXT /T
  72.  
  73. causes the last 10 lines of SVP_TXT to be shown on the screen.
  74.  
  75.                 HEAD SVP_TXT 25 /T > TEMP
  76.  
  77. or
  78.                 HEAD SVP_TXT /T 25 > TEMP
  79.  
  80. places the last 25 lines in a file called TEMP.  Note the file name
  81. must come first; the order of arguments after that does not matter.
  82.  
  83.             Incidentally, there is no restriction on the number of
  84. lines.  I tried HEAD SVP_TXT /T 4000 and found it worked!
  85.  
  86.  
  87. ≡≡≡≡->> QUESTION:
  88.             Input the DOS command "COPY HEAD.C HEAD2.C".  Then
  89.             revise HEAD2.C so that no file is named, and standard
  90.             input is the source of data.  Compile the result and
  91.             experiment with it.  The arguments are simpler, and
  92.             their order doesn't matter.  What are the dangers of
  93.             using HEAD2.C in a DOS environment?
  94.                                                             <<-≡≡≡≡
  95.  
  96. ≡≡≡≡->> QUESTION:
  97.             Make another copy of HEAD.C and call it TAIL.C.  Edit
  98.             it so that the resulting program needs no "/t" argument
  99.             and always shows the end of a file.  Experiment.
  100.                                                             <<-≡≡≡≡
  101.  
  102.  
  103.             Occasionally you might have text containing legitimate
  104. accented characters.  To demonstrate the "/a" (accents) argument:
  105.  
  106.                 HEAD SVP_TXT 150 /A > TEMP
  107. then
  108.                 HEAD TEMP /T
  109. then
  110.                 HEAD TEMP /T /A
  111.  
  112. What's really happening here?  You are taking the top 150 lines of
  113. a file, storing it in a separate temporary file, then displaying
  114. the last 10 lines of the temporary file (that is, lines 141 to 150
  115. of the original file) on the screen.  This is a way of showing an
  116. intermediate part of a file... not as fast as CPB (copy bytes), but
  117. convenient.  When you try the last two commands above, do you
  118. notice the difference between the two displays?  HEAD TEMP /T
  119. includes a word that looks like H^tel; when accents are requested
  120. in HEAD TEMP /T /A, the same word comes out as Hôtel.
  121.  
  122.  
  123. ≡≡≡≡->> QUESTION:
  124.             The experiment fails if you build the temporary file
  125.             without the /A argument (HEAD SVP_TXT 150 > TEMP).  Why
  126.             does it fail?
  127.                                                             <<-≡≡≡≡
  128.  
  129.             On a non-text file, HEAD may either show a lot of caret
  130. ("^") characters, or conclude that a HEAD display is meaningless. 
  131. That information is worth the few seconds used to input the command
  132. and see the result.
  133.  
  134.  
  135.         ═════════════════════════
  136. 5.2           Non-DOS files
  137.         ═════════════════════════
  138.  
  139.             Suppose you display the head of a file and find it
  140. looks like this:
  141.  
  142.  
  143. Fourscore and seven years ago,
  144.                               our forefathers brought forth
  145.                                                            upon
  146.  this continent
  147.                a new nation,
  148.                             conceived in liberty,
  149.                                                  and dedicated
  150. to the proposition
  151.                   that all men are created equal.
  152.  
  153.  
  154. This sample is not 80 characters wide, but you get the idea.  Each
  155. new line starts where the last one left off, and lines wrap around
  156. onto the next line when the right margin is reached.  This effect
  157. is common when UNIX files are brought into a DOS environment.  DOS
  158. needs a carriage return to match each linefeed chararacter.
  159.  
  160.             Here's a simple solution:
  161.  
  162. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  163. usage:  dosify file_name[s]
  164.  
  165.         Replaces a UNIX-style file with a copy in which each
  166.         line feed is preceded by one carriage return, and the
  167.         file ends with one CTL-Z byte.  Use this program on a
  168.         file in which the MORE command produces a skewed listing
  169.         that fails to go back to the left margin for new lines.
  170.  
  171. input:  Any printable ASCII file[s].
  172.  
  173. output: The same file, with the same name, with DOS conventional
  174.         line ends and end of file.
  175.  
  176. writeup: MIR TUTORIAL ONE, topic 5
  177. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  178.  
  179.             You can dosify a clutch of files in one command:
  180.  
  181.                 DOSIFY GETTYSBU.RG LINCOLN DOUGLAS WHATEVER
  182.  
  183. and the display begins to make sense:
  184.  
  185.                 Fourscore and seven years ago,
  186.                 our forefathers brought forth
  187.                 upon this continent
  188.                 a new nation,
  189.                 conceived in liberty,
  190.                 and dedicated to the proposition
  191.                 that all men are created equal.
  192.  
  193. DOSIFY appears to change files in place.  In reality it makes a
  194. copy, and if successful, destroys the original and changes the name
  195. of the copy to match the original.
  196.  
  197.  
  198. ≡≡≡≡->> QUESTION:
  199.             Using A_BYTES on a non-DOS file, how would you
  200.             calculate in advance the number of bytes that it will
  201.             contain after it is dosified?
  202.                                                             <<-≡≡≡≡
  203.  
  204.  
  205.         ═════════════════════════════════════
  206. 5.3           Displaying printable data
  207.         ═════════════════════════════════════
  208.  
  209.             Our immediate objective is to get first impressions of
  210. the content of a file.  F_PRINT is a filter to show only printable
  211. characters within a file.  Unlike HEAD, it can start instantly at
  212. any point within a file.  An accent argument extends the range to
  213. include accented (high-bit-set) characters, but not graphics.
  214.  
  215. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  216. usage   f_print file_name [/a][/w] [ from_byte  to_byte ] > subset
  217.  
  218.         Reduces a file to printable characters only.  If the /w
  219.         option is specified, strings of printable characters that
  220.         are unlikely to be words are filtered out as well, and each
  221.         new burst of accepted text is placed on a new line. /a
  222.         causes accented characters to be accepted as printable.
  223.  
  224. input:  Any file whatsoever, or any part of a file.
  225.  
  226. output: Printable subset.
  227.  
  228. writeup: MIR TUTORIAL ONE, topic 5
  229. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  230.  
  231.             The command
  232.  
  233.                 F_PRINT SVP_TXT /A 121500 121700
  234.  
  235. causes the following display.  Note the accented byte in the two
  236. repetitions of Luçon.
  237.  
  238. CENT <P10>D<P8>EPAUL<R>i.s.C.M.
  239. @TEXT60 = <MI>Addressed:<D> Monsieur Le Soudier, Priest of the
  240. Mission of Luçon, in Luçon
  241. @HEAD4 = 464. - TO N.
  242. @TEXT4 = Saint-Lazare, Sunday, July 29, 1640
  243. @TEXT7
  244.  
  245.             For some fun, try F_PRINT on an executable EXE file,
  246. first without the /W argument, then with /W.  For example,
  247.  
  248.                 F_PRINT F_PRINT.EXE
  249. and
  250.                 F_PRINT /W F_PRINT.EXE
  251.  
  252. The second listing is much shorter and far more intelligible.
  253.  
  254.  
  255. ≡≡≡≡->> QUESTION:
  256.             In what ways might you amend source code in F_PRINT.C
  257.             to get other useful effects?  Hint:  Try variations in
  258.             the function check_store.
  259.                                                             <<-≡≡≡≡
  260.  
  261.  
  262.         ═══════════════════════════════
  263. 5.4           Detailed data dumps
  264.         ═══════════════════════════════
  265.  
  266.             Let's move beyond first impressions to methods of
  267. displaying exactly what byte sequences occur in a file or part of
  268. a file.
  269.  
  270. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  271. Usage   dump file_name [/a] [ from_byte [ to_byte ] ] > report
  272.  
  273.         Lists the contents of a specified portion of any file,
  274.         reporting 16 bytes per line.  "/a" causes accented high bit
  275.         characters to be printed.
  276.  
  277. input:  Any file whatsoever.
  278.  
  279. output: Printable ASCII report, listing offset, then 16 bytes in
  280.         hexadecimal format, with printable ASCII on the right; 
  281.         periods substitute for non-printable bytes.
  282.  
  283. writeup: MIR TUTORIAL ONE, topic 5
  284. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  285.  
  286.             DUMP permits commands such as:
  287.  
  288.                 DUMP SVP_TXT 0 800 > TOP_END
  289.  
  290. This preliminary test of the file can be tried on any portion of
  291. the file.  Moreover, if your target has 367 or fewer bytes, you can
  292. send the output directly to the screen without worrying about CTL-S
  293. stop and go control, as in:
  294.  
  295.                 DUMP SVP_TXT 100000 100366
  296.  
  297.             DUMP restricts the printable character set to the 95
  298. byte patterns ranging from hex 20 (space) up to hex 7E.  This
  299. restriction makes it much easier to recognize ordinary text; it is
  300. not surrounded by a jumble of happy faces and graphic characters. 
  301. (Try the DOS 5.0 MORE command on any EXE executable file and see
  302. what you get!)  Other characters are in the strict sense
  303. printable... carriage returns, line feeds and tabs.  For accented
  304. characters using PC compatible extended ASCII, add the accents
  305. argument "/a":
  306.  
  307.                 DUMP SVP_TXT /A 11100 11200
  308.  
  309. Note the accented French word "écus" in the result.
  310.  
  311.  
  312.         ═══════════════════════════════════════════
  313. 5.5           Convenient display of fragments
  314.         ═══════════════════════════════════════════
  315.  
  316.             Suppose we want to check out other high-bit-set bytes
  317. found in the file SVP_TXT.  Here is the list created by A_BYTES:
  318.  
  319. é    [82]     43   0.0%   11144 12314 13915 14831 18658 23503
  320.                           23800 26370
  321. â    [83]      1   0.0%   207322
  322. à    [85]      1   0.0%   116508
  323. ç    [87]      7   0.0%   95180 109218 121610 121620 129909
  324.                           175862 181966
  325. è    [8A]      4   0.0%   130386 130571 161305 232659
  326. î    [8C]      4   0.0%   65079 93876 95582 138200
  327. ô    [93]     10   0.0%   8834 16736 28121 28656 97731 134953
  328.                           163316 170678
  329.  
  330.             One way to display a byte at a known location with its
  331. context is to issue a DUMP command that straddles its location. 
  332. For example, to view the ç with cedilla at offset 95180:
  333.  
  334.                 DUMP SVP_TXT /A 95100 95300
  335.  
  336. would do the job.  But DUMP gives too much detail for this purpose.
  337. The key lines in the screen display are:
  338.  
  339. 95164: 79 65 3c 5e 3e 39 3c 44 3e 20 69 6e 0d 0a 4c 75
  340.                                                 ye<^>9<D> in  Lu
  341. 95180: 87 6f 6e 3f 3c 5e 3e 31 30 3c 44 3e 20 49 20 66
  342.                                                 çon?<^>10<D> I f
  343. 95196: 69 6e 64 20 69 74 20 64 69 66 66 69 63 75 6c 74
  344.                                                 ind it difficult
  345.  
  346.             A more convenient program is FRAGMENT:
  347.  
  348. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  349. Usage   fragment  input_file  offset  > stdout
  350.  
  351.         Display a five line fragment of a file in printable form
  352.         with two lines of context on either side of the selected
  353.         offset.  Useful to get a quick view of contents at a
  354.         selected location in a file.  Use CPB and/or DUMP for an
  355.         alternate method, less convenient, but with more detail.
  356.  
  357. input:  Most useful for printable ASCII files.
  358.  
  359. output: Five double spaced lines in which  non-printing characters
  360.         are shown as blank with a ^ in the blank line below.  The
  361.         character at the exact offset is marked by a | in the blank
  362.         line below.
  363.  
  364. writeup: MIR TUTORIAL ONE, topic 5
  365. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  366.  
  367.             To display context of the first ç at offset 95180,
  368. simply input:
  369.                 FRAGMENT SVP_TXT 95180
  370.  
  371. Five lines are displayed; the third line starts this way:
  372.  
  373.             Luçon?<^>10<D> I find it difficult to
  374.               |
  375.  
  376. Notice how the ç is highlighted by the vertical bar | immediately
  377. underneath.
  378.  
  379.             Try showing the î at byte 138200 with this command:
  380.  
  381.                 FRAGMENT SVP_TXT 138200
  382.  
  383. You are shown the context around:
  384.  
  385.                 M. Benoît<^>2<D> does not return
  386.                        |
  387.  
  388. and again a vertical bar underneath draws attention to the î.
  389.  
  390.             FRAGMENT works for any ASCII file, particularly where
  391. line lengths are under 80 characters.  (Unix users:  Many terminals
  392. are unpredictable when they attempt to display bytes with the high
  393. bit set.  The source code contains notes indicating where to make
  394. necessary changes.)  In the SVP_TXT example, the locations shown
  395. above all check out as valid accented characters within French
  396. names.  Further along, we will find that by using the program
  397. A_PATTRN we can verify that all bytes with high bit set in our
  398. sample SVP_TXT are valid.
  399.  
  400.  
  401.         ══════════════════════════════════════════════
  402. 5.6           Viewing patterns throughout a file
  403.         ══════════════════════════════════════════════
  404.  
  405.             The techniques thus far display context at specific
  406. points within a file... the beginning, the end, or near certain
  407. offsets.  More is needed.  We want to be able to:
  408.  
  409.         »   ensure that patterns are consistent across all the
  410.             data;
  411.  
  412.         »   identify every set of codes and signals that may help
  413.             us toward our objectives of interpreting record and
  414.             field separators, searchable content, etc.
  415.  
  416.             At the end of the preceding topic, we concluded that
  417. our sample file, SVP_TXT, is extended ASCII text (normal text plus
  418. accented letters), and that the usage of certain characters needs
  419. to be checked out:  @  =  ^  |  <  >.
  420.  
  421.             The program A_PATTRN can be used to isolate every
  422. occurrence within a file of a single character or of a string of up
  423. to 16 characters.
  424.  
  425.  
  426. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  427. usage: a_pattrn  file_name  key  [ /x ] [ bytes_before ] > report
  428.              "/x" = include hex, show only 16 bytes instead of 40
  429.     List every occurrence of a key character or string in a file.
  430.     Show 3 (or "bytes_before", range 0 to 15) bytes prior to the
  431.     key each time.  Normally show a total of 40 bytes each time
  432.     the key is found; if the "/x" argument is set, show only 16
  433.     bytes, but in hex and ASCII both.  The key may be from 1 to
  434.     16 characters.  Within the key, any non-printing characters,
  435.     characters which may confuse DOS (> or < or |), linefeeds,
  436.     blanks, backslash, etc. must be shown in hex form...  a
  437.     backslash and 2 hex digits.  Examples:
  438.             a_pattrn herfile  \8E  >  herfile.8e
  439.             a_pattrn yourfile  *  7  >  yourfile.ast
  440.             a_pattrn myfile  Mother
  441.             a_pattrn hisfile  \94\05ke\ff  0  >  5char.pat
  442.  
  443. input:  Any file whatsoever.
  444.  
  445. output: One line for each occurrence of the target byte(s) in the
  446.     file.  Sort the result to make patterns show up more clearly.
  447. writeup: MIR TUTORIAL ONE, topic 5
  448. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  449.  
  450.             DOS assigns meaning to certain characters (such as
  451. space, | < >, etc.), so if you have any problem using the A_PATTRN
  452. command, switch to the hex format for the search key (the letter or
  453. sequence of letters on which you wish to search).  For example,
  454.  
  455.                 A_PATTRN SVP_TXT > > SVP3E
  456. fails, but
  457.                 A_PATTRN SVP_TXT \3E > SVP.3E
  458. works.
  459.  
  460.             The key benefit of A_PATTRN is that it selects the same
  461. byte or string and places it in the same position on each line.
  462. Patterns begin to emerge at once.  Here are the first few lines
  463. produced by:
  464.  
  465.                 A_PATTRN SVP_TXT \3C\5E > RESULT
  466.  
  467.         00000641:    men<^>2<D> want to communicate..in writi
  468.         00001138:    ot]<^>3<D> concern the hospital, you..ca
  469.         00001467:    uf,<^>4<D> on Madame..Goussault's<^>5<D>
  470.         00001497:    t's<^>5<D> estates, I believe, although 
  471.         00001678:    eu,<^>6<D> and to do so as soon as possi
  472.         00002197:    ne,<^>2<D> which I see from your..letter
  473.         00003152:    is;<^>3<D> who put together his council 
  474.         00003412:    us?<^>4<D> Indeed, there is no good or..
  475.         00003747:    ey,<^>5<D> who on another..occasion spok
  476.         00005086:    eva<^>6<D> and,..following his example, 
  477.  
  478. \3C\5E appears as <^ starting at byte 17 in each line.  It is a
  479. simple matter to perform a sort:
  480.  
  481.                 SORT /+17 < RESULT > RESULT.SRT
  482.  
  483.             The hexadecimal output from A_PATTRN (when argument /x
  484. is used) looks just like the output of DUMP.  Here we have
  485. shortened the lines a bit.
  486.  
  487. 00000641: 6d 65 6e 3c 5e 3e 32 3c 44 3e 20...    men<^>2<D> want 
  488. 00001138: 6f 74 5d 3c 5e 3e 33 3c 44 3e 20...    ot]<^>3<D> conce
  489. 00001467: 75 66 2c 3c 5e 3e 34 3c 44 3e 20...    uf,<^>4<D> on Ma
  490. 00001497: 74 27 73 3c 5e 3e 35 3c 44 3e 20...    t's<^>5<D> estat
  491. 00001678: 65 75 2c 3c 5e 3e 36 3c 44 3e 20...    eu,<^>6<D> and t
  492. 00002197: 6e 65 2c 3c 5e 3e 32 3c 44 3e 20...    ne,<^>2<D> which
  493. 00003152: 69 73 3b 3c 5e 3e 33 3c 44 3e 20...    is;<^>3<D> who p
  494. 00003412: 75 73 3f 3c 5e 3e 34 3c 44 3e 20...    us?<^>4<D> Indee
  495. 00003747: 65 79 2c 3c 5e 3e 35 3c 44 3e 20...    ey,<^>5<D> who o
  496. 00005086: 65 76 61 3c 5e 3e 36 3c 44 3e 20...    eva<^>6<D> and,.
  497.  
  498. The hex result can also be sorted (SORT /+20).  When dealing with
  499. fully printable files, the hex rendition of each byte is not
  500. particularly useful.  The one piece of information the hex version
  501. provides is that the ".." pattern within the ASCII is usually a
  502. line feed - carriage return combination.
  503.  
  504.             Whichever output is selected, we discover that the two
  505. bytes "<^" in the file SVP_TXT are in every case followed by ">",
  506. a one or two digit number, then "<D>".  The lowest numbers, 1 and
  507. 2, are most frequent.  The frequency falls off steadily so that the
  508. highest, "<^>27<D>" occurs only once.
  509.  
  510.             Looking at the patterns around the single character hex
  511. 3C ("^") alone reveals two other combinations:  "<B^>#<D>" and
  512. "<I^>#<D>".  The three basic patterns <^>, <B^> and <I^> account
  513. for all occurrences of the caret character "^".
  514.  
  515. ≡≡≡≡->> QUESTION:
  516.             DOS 5.0 has a "FIND" command which can also be used to
  517.             list every line in which a character sequence appears. 
  518.             Compare the respective advantages of FIND and A_PATTRN.
  519.                                                             <<-≡≡≡≡
  520.  
  521.  
  522.         ═════════════════════════════════════════
  523. 5.7           The power of sorting patterns
  524.         ═════════════════════════════════════════
  525.  
  526.             Suppose we look for patterns around the single "at
  527. sign" (@) character:
  528.  
  529.                 A_PATTRN SVP_TXT @ > AT_SIGN.SVP
  530.  
  531. The result contains 935 lines which start out as follows:
  532.  
  533.         00000000:    ...@HEAD1 = SAINT VINCENT DE PAUL..@HEAD
  534.         00000032:    L..@HEAD2 = CORRESPONDENCE..@HEAD4 = 417
  535.         00000057:    E..@HEAD4 = 417. - TO SAINT LOUISE DE MA
  536.         00000121:    S..@TEXT4 = Paris, January 11, 1640..@TE
  537.         00000155:    0..@TEXT7 = Mademoiselle,..@TEXT6 = I re
  538.         00000179:    ,..@TEXT6 = I received three letters fro
  539.         00000605:    ...@TEXT6 = Seeing that those Gentlemen<
  540.         00001613:    ...@TEXT6 = You would do well to send fo
  541.         00001799:    ...@TEXT6 = People are praying to God fo
  542.         00001941:    ...@HEAD4 = 418. - TO LOUIS ABELLY,<B^>1
  543.  
  544. We may have tripped upon the record separators and field separators
  545. that we are looking for.  Notice particularly the pattern @HEAD4 =
  546. which is followed by a number.  We have several options at this
  547. point.  One is to lengthen the key and re-run the pattern analysis:
  548.  
  549.                 A_PATTRN SVP_TXT @HEAD > AT_HEAD.SVP
  550. and
  551.                 A_PATTRN SVP_TXT @TEXT > AT_TEXT.SVP
  552.  
  553.             Alternately, since the earlier listing AT_SIGN.SVP has
  554. only 51,425 bytes, we can sort it beginning at column 17:
  555.  
  556.                 SORT /+17 < AT_SIGN.SVP > AT_SIGN.SRT
  557.  
  558. As we view the sorted result, patterns become very clear.  Here is
  559. part of the analysis that I reported after a few more tests with
  560. the A_PATTRN program.  At this point, analysis was still tentative,
  561. but it provided a good basis for discussion with the database
  562. provider.
  563.  
  564.  
  565.                        Analysis of SVP_TXT
  566.             ASCII text with Printer's Codes (Headers)
  567.  
  568.                                                 February 12, 1992
  569.  
  570.             The following are tentative interpretations to the
  571. Printer's Codes embedded in SVP_TXT.  Corrections to errors would
  572. be welcome.
  573.  
  574.         @HEAD1      database heading, 1 occurrence at beginning
  575.         @HEAD2      database subheading, 1 occurrence   "
  576.         @HEAD4      sequence number, 1 per letter
  577.         @TEXT31     dateline
  578.         @TEXT4      dateline, letter from s.v.p.
  579.         @TEXT41     dateline, letter to s.v.p. from other person
  580.         @TEXT5      signature line, s.v.p.
  581.         @TEXT51     signature line, other person
  582.         @TEXT6      paragraph start, letter from s.v.p.
  583.         @TEXT60
  584.         @TEXT600
  585.         @TEXT61     paragraph start, letter from other person
  586.         @TEXT611    address line to s.v.p.
  587.         @TEXT7      salutation from s.v.p.
  588.         @TEXT71     salutation to s.v.p.
  589.         <169>       beginning quote  (7X)
  590.         <170>       end quote  (7X)
  591.         <197>       dash  (23X)
  592.         <B^>1<D>    superscript footnote ref in heading  (11X)
  593.         <D>         terminator for other < > symbols  (594X)
  594.         <I^>#<D>    superscript footnote ref in heading  (59X)
  595.         <M>         emphasis -- bold, highlight, italics?  (6X)
  596.         <MI>        emphasis -- bold, etc.?  (134X)
  597.         <P10>, <P7>, <P7M>, <P8>, <P8MI>, <P9>
  598.                     pica measures for font size  (212X)
  599.         <R>         ??  18 of 21X  <R>i.s.C.M. in signature
  600.         <^>#<D>     superscript footnote ref in text  (409X)
  601.         <|>         blank position holder, not to end line  (28X)
  602.  
  603.  
  604.         ═══════════════════════════════
  605. 5.8           Sorting large files
  606.         ═══════════════════════════════
  607.  
  608.             As files get larger, the DOS SORT slows down.  Sorting
  609. the 935 lines (51,425 bytes) in AT_SIGN.SVP took 30 seconds on a 12
  610. megahertz AT clone.  As the SORT 64k byte limit is approached,
  611. things fall apart.
  612.  
  613.             A description follows for SORT2, a device to get around
  614. the 64k limit.  It's not elegant, but it works!  
  615.  
  616. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  617. Usage -  sort2 [/r] [/+n] from_file to_file key[s]
  618.  
  619.     Sorts large ASCII text files using the memory-bound DOS SORT
  620.     routine in multiple passes.  /r signifies reverse order.
  621.     /+n specifies a starting column, 1-999.  A key is 1 to 3
  622.     characters, used as a dividing point.  The program separates
  623.     the input file into a series of temporary files, depending on
  624.     the byte(s) at the starting column.  For n dividing points,
  625.     the program makes n+1 temporary files, and reports the size
  626.     of each.  If all are under 60k characters, they are sorted
  627.     and placed together in the output file.  If a run fails, add
  628.     another dividing point mid-way in the range that fails (that
  629.     is, the file that is too big), and try again.  NOTE:  The DOS
  630.     SORT starts column count at 1, converts all lower to upper
  631.     case!
  632.  
  633. input:  Line oriented printable ASCII.
  634.  
  635. output: Same file, sorted.
  636.  
  637. writeup: MIR TUTORIAL ONE, topic 5
  638. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  639.  
  640.  
  641. ≡≡≡≡->> QUESTION:
  642.             Try out SORT2, get a feel for how it works.  Can you
  643.             come up with ways to make it easier to use or more
  644.             powerful?  Or do you have your own super sort that you
  645.             are willing to publish under copyleft rules?
  646.                                                             <<-≡≡≡≡
  647.  
  648.             Another way to speed up sorts is to throw away portions
  649. of the target file that are not essential for the purpose you have
  650. in mind when sorting.  For example, the program A_PATTRN produces
  651. 8 byte offsets followed by a colon and white space, and up to 40
  652. bytes of information.  Are they all necessary?
  653.  
  654.             The program COLRM removes the same columns from every
  655. line of ASCII text in a file:
  656.  
  657.  
  658.  
  659.  
  660. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  661. Usage - colrm from_col to_col < printable_ascii > revised_ascii
  662.  
  663.         Removes the specified range of columns from each line of an
  664.         ASCII file.  This is a clone of the Unix "colrm" utility.
  665.  
  666. input:  A printable ASCII file with less than 512 characters per
  667.         line.  Columns number from 1 upward.
  668.  
  669. output: The same number of lines, but with one segment of columns
  670.         removed from each line.
  671.  
  672. writeup: MIR TUTORIAL ONE, topic 5
  673. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  674.  
  675.             Since ASCII text is the only accepted input, we are
  676. safe in a DOS environment to use standard input and output.  There
  677. is no confusion over line feeds and CTL-Z characters.  An added
  678. benefit is that we can pipe the output of successive runs of COLRM.
  679.  
  680.             Recall the earlier example
  681.  
  682.                 A_PATTRN SVP_TXT \3C\5E > RESULT
  683.  
  684. which produced output that started off like this:
  685.  
  686. 00000641:    men<^>2<D> want to communicate..in writi
  687. 00001138:    ot]<^>3<D> concern the hospital, you..ca
  688. 00001467:    uf,<^>4<D> on Madame..Goussault's<^>5<D>
  689. 00001497:    t's<^>5<D> estates, I believe, although 
  690. 00001678:    eu,<^>6<D> and to do so as soon as possi
  691. 00002197:    ne,<^>2<D> which I see from your..letter
  692. 00003152:    is;<^>3<D> who put together his council 
  693. 00003412:    us?<^>4<D> Indeed, there is no good or..
  694. 00003747:    ey,<^>5<D> who on another..occasion spok
  695. 00005086:    eva<^>6<D> and,..following his example, 
  696.  
  697.             Our primary interest is in the patterns of the form
  698. <^>#<D> and <^>##<D>.  We could remove the first 16 columns by:
  699.  
  700.                 COLRM 1 16 < RESULT > TEMP
  701.  
  702. and those that follow the 8 characters of interest by
  703.  
  704.                 COLRM 9 99 < TEMP > RESULT2
  705.  
  706. Notice that you can use any large number that will reach to the end
  707. of all lines.  Alternately, you can do the two steps in one:
  708.  
  709.                 COLRM 1 16 < RESULT | COLRM 9 99 > RESULT2
  710.  
  711. RESULT2 has only 4,090 bytes, in contrast to the 22,086 in RESULT. 
  712. The new file starts off like this:
  713.  
  714. <^>2<D>
  715. <^>3<D>
  716. <^>4<D>
  717. <^>5<D>
  718. <^>6<D>
  719. <^>2<D>
  720. <^>3<D>
  721. <^>4<D>
  722. <^>5<D>
  723. <^>6<D>
  724.  
  725. Eighty per cent reduction in a file size pays off when sorting.
  726.  
  727.             A_OCCUR is useful in analyzing sorted files that
  728. contain many repetitions.
  729.  
  730. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  731. Usage - a_occur [ min_freq ] [ /n ]  < ascii_text > report
  732.              /n = non-sequenced data is okay
  733.  
  734.         Count the frequency of occurrence of identical lines
  735.         If a minimum frequency is specified, lines occurring
  736.         fewer times are dropped entirely from the result.
  737.  
  738. Input:  ASCII text, which must be in sorted order UNLESS the
  739.         flag "/n" is included.
  740.  
  741. Output: A reduced copy of the file with each line shown only
  742.         once.  Each line begins with a frequency count, padded
  743.         out to six characters with blanks.
  744.  
  745. Writeup: MIR TUTORIAL ONE, topic five.
  746.          See also the related programs A_OCCUR2 and A_OCCUR3.
  747. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  748.  
  749.             Here is the top end of the output when we input the
  750. command
  751.                 A_OCCUR < RESULT2 > FREQ
  752.  
  753.  
  754. 10  <^>10<D>
  755. 8   <^>11<D>
  756. 6   <^>12<D>
  757. 5   <^>13<D>
  758. 5   <^>14<D>
  759. 3   <^>15<D>
  760. 3   <^>16<D>
  761. 3   <^>17<D>
  762. 2   <^>18<D>
  763. 2   <^>19<D>
  764.  
  765. Frequency is the first element.  For example, the pattern <^>11<D>
  766. occurs 8 times, <^>12<D> occurs 6 times.  It was the regularly
  767. declining frequency of the numbers that first suggested to me that
  768. these tags indicate footnote numbers within the test file SVP_TXT.
  769.  
  770.             To finish this topic, we mention two simple utility
  771. programs that are related to A_OCCUR.
  772.  
  773. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  774. usage - a_occur2  [ min_frequency [ filename_under_min ] ]
  775.               < merged a_occur files > combined
  776.  
  777.         A utility to calculate cumulative frequency of
  778.         merged A_OCCUR outputs.  If a minimum frequency is
  779.         specified, then all lower frequency items are either
  780.         suppressed or sent to a file named in the next argument.
  781.  
  782. Input:  ASCII text, in which each line starts with a number
  783.         (a frequency count) followed by blanks, then sorted text
  784.         starting in the seventh column.
  785.  
  786. Output: A copy of the same file in which multiple identical lines
  787.         are shown only once, preceded by the combined frequency
  788.         count.
  789.  
  790. Writeup: MIR TUTORIAL ONE, topic five.
  791. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  792.  
  793.  
  794. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  795. Usage   a_occur3 < occur_file > expanded_file
  796.  
  797.         Reverse an A_OCCUR file by removing the initial count,
  798.         then outputting each line the number of times indicated
  799.         by the count.  Useful if editing an A_OCCUR file, then
  800.         reconstituting it.
  801.  
  802. input:  ASCII file with each line containing a count, blank
  803.         padded to the sixth character, then the line content.
  804.  
  805. output: Same content, but with leading six characters removed
  806.         and content repeated for "count" lines.
  807.  
  808. Writeup: MIR TUTORIAL ONE, topic five.
  809. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  810.  
  811.  
  812.                           *  *  *  *  *
  813.  
  814.  
  815.             We have identified several methods of viewing portions
  816. of a computer file.  Each is an aid in analyzing file content.  The
  817. most powerful aid is the A_PATTRN program.  Its output may be
  818. sorted so that the context of any character or sequence of up to 16
  819. characters may be examined.
  820.  
  821.             Interpreting the results becomes easier as you acquire
  822. experience with various kinds of data.  The next few topics offer
  823. additional tools and pointers for analysis.
  824.