home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / zgrep11.lbr / ZGREP11.DZC / ZGREP11.DOC
Encoding:
Text File  |  1993-10-25  |  17.1 KB  |  459 lines

  1. ZGREP11.DOC      7/20/88    Richard Brewster
  2.  
  3. ZGREP11.COM is a version of the UNIX utility GREP which searches 
  4. for a pattern in a file or group of files and prints out the 
  5. lines in which the pattern is found.  It is an acronym for
  6.  
  7.           Global Regular Expression Print
  8.  
  9. ZGREP11 is a sibling of ZCOPY20 and ZERA10.  In addition to 
  10. pattern searching ZGREP can copy, concatenate, list, and line 
  11. number ASCII files.
  12.  
  13. The general invocation of ZGREP is -
  14.  
  15. A0>ZGREP "expression" afn {afn...} {>outfile} {[flags}
  16.  
  17. The arguments in braces above are optional.  (The braces
  18. themselves should not be typed on the actual command line.)
  19.  
  20. You can rename ZGREP11.COM to ZG.COM.  This is how the examples 
  21. are shown below.  Typing the program name with no arguments prints
  22. a help screen -
  23.  
  24. A0>ZG >ZGHELP.TXT   (creates the file ZGHELP.TXT)  -or-
  25. A0>ZG >LST:         (sends the help text to your printer)
  26.  
  27. 1.   Option Flags
  28.  
  29. [N [Q [V and [F are option flags
  30.  
  31. [N (Number) prints the line number of each line found
  32. [Q (Query)  queries the user before searching files
  33. [V (inVert) prints lines which do NOT match the expression
  34. [F (Formfeed) sends a formfeed to the output after each search
  35.    (The console bell also sounds whenever a formfeed is sent.)
  36.  
  37. Flags may appear in any position on the command line.
  38.  
  39. A0>ZG [n "exp" file           - is equivalent to -
  40. A0>ZG "exp" [n file
  41.  
  42. A0>ZG [nvf "exp" file          - is the same as -
  43. A0>ZG [n "exp" [f file [v
  44.  
  45. 2.   Filespec List
  46.  
  47. The filespec list can be any number of filespecs, separated by 
  48. spaces.  Each filespec may be ambiguous.  For example -
  49.  
  50. A1>ZG "exp" b:text.fil c12:*.let 2:foo.doc a:read.me
  51.  
  52. would search for "exp" in TEXT.FIL on drive B1:, all files with 
  53. the type of .LET on drive C12:, in C2:FOO.DOC, and A2:READ.ME.  
  54. Drive and user begin with the logged values, and then default to 
  55. the last specified along the list.
  56.  
  57. Messages indicate which file is currently being searched.  
  58. Filespecs are searched in the order they appear on the command 
  59. line.  Each filespec may match up to a maximum of 100 files, and 
  60. you can increase this number by patching ZG.COM, see below.
  61.  
  62. Wild USER number is also allowed -
  63.  
  64. A0>ZG "exp" B*:*.DOC
  65.  
  66. will search in all .DOC files in all user areas of B:
  67.  
  68. 3.   Redirected Output to File or Printer
  69.  
  70. A0>ZG "exp" text.fil >b3:out.txt
  71.  
  72. will search A0:TEXT.FIL for "exp" and place all lines in which 
  73. "exp" is found into B3:OUT.TXT
  74.  
  75. The '>' must precede the outfile spec with no intervening space.  
  76. The output redirective may appear in any position on the command 
  77. line.
  78.  
  79. A0>ZG "exp" *.txt >lst: [f
  80.  
  81. will send the output to the CP/M list device, separating the 
  82. output from each file search with a formfeed.  CON:, and PUN:  
  83. are also supported, but are probably of limited use.
  84.  
  85. If output is redirected, error and processing messages will still 
  86. be sent to the CP/M console.  Only the lines matched in the 
  87. search file will be sent to the redirected output.  This allows 
  88. some special applications such as file copying, concatenating, 
  89. and line numbering - see below how to do this. 
  90.  
  91. 4.   "Regular Expression"
  92.  
  93. The most complex and versatile aspect of ZGREP is the "regular
  94. expression" which specifies the search pattern.  The expression is
  95. the first command line argument which is not preceded by a '[' or 
  96. a '>'.  But this does not limit the search pattern because '\[' 
  97. will start the pattern off with '['.  In fact the backslash, '\' 
  98. is one of a number of special characters you need to know.
  99.  
  100. Double and single quotes (" and ') are command line argument 
  101. delimiters, along with space and tab.  If you enclose the entire 
  102. expression in quote marks, you may include spaces in the 
  103. expression (if your CCP allows).  You can even search for a 
  104. pattern that starts with a single or double quote mark, either by 
  105. preceeding it with '\', or by enclosing the whole expression in 
  106. the other type of quote mark, e.g.
  107.  
  108. A0>ZG '"hello" there' text.fil        - or -
  109. A0>ZG \"hello"_there text.fil
  110.  
  111. will both search for the pattern <"HELLO" THERE> in TEXT.FIL, 
  112. including the double quote marks in the search pattern.
  113.  
  114. The only difference in the second example is that a tab as well 
  115. as a space between <"HELLO"> and <THERE> will match.
  116.  
  117. ALL COMPARISONS DISREGARD THE CASE OF ALPHABETIC CHARACTERS.
  118.  
  119. Any character not described below as special just represents 
  120. itself in the search pattern, but alphabetic case is ignored.
  121.  
  122. \    preceding a character will quote that character as it is, 
  123.      i.e. will remove any special meaning that it otherwise would
  124.      have.  It even can be applied to itself: '\\' will enter the
  125.      backslash character into the search pattern.
  126.  
  127. ^    preceding an ALPHABETIC character, or one of [\]^_?, will 
  128.      enter the corresponding control character into the search 
  129.      pattern with the exception of ^J, ^M, and ^Z, since all of 
  130.      these are line terminators and can never be found inside a 
  131.      line of ASCII text.  If you try to enter one of these or any 
  132.      other disallowed control character, you will receive an 
  133.      error message and ZGREP will abort, saving you from 
  134.      searching for an unmatchable string.
  135.  
  136.      NOTE:  the combination ^\ is a special case which represents 
  137.      a control character.  Do not use ^\\ for this.  The same 
  138.      applies for ^[, ^], ^^, and ^_.  ^? represents DEL.
  139.  
  140. |    at the beginning of the expression matches the beginning of
  141.      a line.
  142.  
  143. $    at the end of the expression matches the end of a line.
  144.  
  145. _    (underline char) will match a space or a tab.
  146.  
  147. ?    will match any single character.
  148.  
  149. :    followed by one of the letters below will match a class (a 
  150.      set) of characters.
  151.  
  152.      :a   will match any alphabetic [a-z]
  153.      :c   will match any control character including DEL (7FH),
  154.           except for TAB (^I).
  155.           (Note that ^@ ^J ^M and ^Z will never be found.)
  156.      :d   will match any digit [0-9]
  157.      :n   will match any alphanumeric [a-z] or [0-9]
  158.      :p   will match any punctuation character, i.e. the set
  159.           !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
  160.  
  161.      These colon classes could be specified explicitly.  For 
  162.      example, [a-z] matches the same set as :a, but the colon 
  163.      specifier executes much faster.
  164.  
  165. []   delimits a class of your choosing, for example [.?!] would 
  166.      find the end punctuation of English sentences.  It makes no 
  167.      difference the order in which characters appear.  If any one 
  168.      of the set is found in the place in the general expression 
  169.      that the class appears, the line will register a match.  For 
  170.      example, "ZCPR[132]" will match "ZCPR1", "ZCPR2", or "ZCPR3".
  171.  
  172.      This same set could be specified as a RANGE by "ZCPR[1-3]".  
  173.      For ranges some special rules apply.  The range 
  174.      delimiter (the dash) must be preceded by a character other 
  175.      than '[', and followed by something other than ']' or '\', 
  176.      or you will get an error message.  Make sure that the range 
  177.      goes from lower to higher in the ASCII set.  Inverse ranges 
  178.      are disallowed because, for example, [c-a] can never match 
  179.      anything.
  180.  
  181.      Ranges may appear anywhere within the class delimiters.  For 
  182.      example, [ql-pbe-h] means the same as [qlmnopbefgh], which 
  183.      is also the same as [befghlmnopq].  (Yes, think about this 
  184.      for a minute.)
  185.  
  186.      Control characters may be included within classes, or used 
  187.      as range starting or ending characters.  [^q-^t] and [^e^]] 
  188.      are valid sets.
  189.  
  190.      Note that '|' '$' '_' '?', ':', '+', and '*' have no special 
  191.      meaning inside of a class set and do not have to be preceded 
  192.      by '\', although you may if you wish.  The only need for the 
  193.      backslash prefix here is to allow entry of '^', '-', ']', or 
  194.      '\' (itself) into the set.
  195.  
  196.      Finally, if the character '!' (chosen to honor all the C 
  197.      programmers) is the first character after the opening 
  198.      bracket, then any character EXCEPT those in the class will 
  199.      be matched.  For example, [!a-z] will match any character 
  200.      that is not alphabetic.  [!!] will match anything but an 
  201.      exclamation point!
  202.  
  203. -    (minus sign) is a special character which must FOLLOW a sub- 
  204.      expression that you want to optionally match.  That is, 
  205.      there can be zero or one occurance of the expression.  For 
  206.      example, the expression ".CQ-_"  will find all lines 
  207.      containing ".C_" and also lines containing ".CQ_"
  208.  
  209. +    FOLLOWING a sub-expression will match one or more occurances 
  210.      of the sub-expression.  For example, "_m:a+e_" will find all 
  211.      lines containing a word that begins with 'M' and ends with 
  212.      'E'.  How about that!  However, this won't find 'ME'.
  213.  
  214. *    FOLLOWING a sub-expression will match ZERO or more 
  215.      occurances of the sub-expression.  "_m:a*e_" will find the 
  216.      same lines as the above, plus those containing the separate 
  217.      word 'ME'.  As another example, "(?*)" will find all 
  218.      parenthesized expressions, including the expression "()".
  219.  
  220. 5.   General Operational Characteristics
  221.  
  222. Number of input files
  223.  
  224. As distributed, ZGREP is limited to processing 100 files for EACH 
  225. ambiguous filespec given on the command line.  If more than 100 
  226. files match an ambiguous filespec, only the first 100 will be 
  227. searched.  Files are searched first in the order of filespecs
  228. given on the command line, and then as they are found in the disk 
  229. directory.  The names list for each filespec is sorted first.
  230.  
  231. ZGREP operates on ASCII files, and any kind of text file can be 
  232. processed.  As characters are read from the file, the high order 
  233. bit is first reset so that only normal ASCII codes (0 to 127) are 
  234. compared.  This is useful for searching WordStar(tm) format files.  
  235. Whenever a linefeed or carriage return is found, the line is 
  236. terminated.  This means that you cannot search for a pattern that 
  237. goes across a line boundary, that is, you cannot include 
  238. linefeeds or carriage returns in your search expression.  But you 
  239. CAN specify the beginning or end of a line in the search string, 
  240. using the '|' and '$' characters.  Lines as long as 512 
  241. characters can be handled.  Control-Z is the normal End of File 
  242. marker, so you can search through binary files only as far as the 
  243. first ^Z.
  244.  
  245. 6.   Indirect Input 
  246.  
  247. Instead of - or in addition to - the filespecs typed on the 
  248. command line, you can create an ASCII text file listing a set of 
  249. files you want searched and then command ZGREP to use it.
  250.  
  251.      ZGREP "exp" <FILELIST
  252.  
  253. will add the text of a file named FILELIST to its command line.  
  254. You must create the indirect file properly for this to work.  
  255. Each line must contain one and only one command line argument.  
  256. For example, if a text file named "USEME" exists on A0: 
  257. containing the following lines -
  258.  
  259. "July :D*, 1988"
  260. b:*.TXT
  261. [Q
  262.  
  263. The command line
  264.  
  265. A0>ZGREP <USEME
  266.  
  267. will do the same thing as
  268.  
  269. A0>ZGREP "July :D*, 1988" b:*.TXT [Q
  270.  
  271. Arguments in the file are ADDED to whatever else you type on the 
  272. command line.
  273.  
  274. Be careful not to put any SPACES after a filespec on a line in 
  275. the indirect file, or it will be an invalid filespec.  Lower case 
  276. letters are converted to uppercase automatically.
  277.  
  278. As a special usage of input redirection, try
  279.  
  280. A0>ZGREP <CON:
  281.  
  282. You will be prompted to enter a column of arguments, just as if 
  283. it were coming from an indirect file.  You must type control-Z 
  284. alone on the last line to terminate input and begin searching.
  285.  
  286. 7.   Query Option
  287.  
  288. The command line option to Query the user before each operation, 
  289. '[Q', causes the program to start in Query mode, which will yield 
  290. a Query of the following form -
  291.  
  292.      Searching FILENAME for "exp" OK?
  293.  
  294. to which you may answer in one of five ways:
  295.  
  296.      Y    searches the file.
  297.      ESC  searches the file, and turns off the Query option, so 
  298.           that all remaining files will be searched.  But see below!
  299.      TAB  skips the remaining files matching the current filespec 
  300.           and goes on to the next filespec, if there is one.
  301.      ^C   exits safely back to CP/M.
  302.      N    (or anything else) skips the file.
  303.  
  304. Even if you did not give the '[Q' flag on the command line, you 
  305. can enter the Query mode any time you like during multiple file 
  306. searches.  Just type ESC, and the next search will give you the 
  307. Query first.  Using ESC you can go back and forth as much as you 
  308. like, toggling the Query mode on and off.
  309.  
  310. If you patch ZGREP.COM to come up normally in Query mode, then 
  311. the [Q flag will cause ZGREP to come up NOT in Query mode.  This 
  312. is also the case for the [N, [V and [F flag options.
  313.  
  314. 8.   Customizing the Screen Display of Control Characters
  315.  
  316. Two sequences of bytes are available to turn display attributes 
  317. on and off for enhancing  the display of control characters.   
  318. The first is sent to the screen before a control character is 
  319. displayed as its ASCII equivalent.  The second is sent just after 
  320. the ASCII character.  These sequences can be set to display a 
  321. printable character of your choice, for example, '^', or to send 
  322. an escape sequence to toggle video attributes on your display.  
  323. For example, you can patch ZGREP.COM so that all control 
  324. characters will be displayed on the Kaypro screen as inverse, low 
  325. intensity video characters.  The locations must be patched 
  326. directly, using DDT, EDFILE, SPZ, etc.
  327.  
  328. Six bytes plus a terminating zero are allotted each for video on
  329. and video off control strings.
  330.  
  331. The video on sequence is located at     018BH
  332. The video off sequence is located at    0192H
  333.  
  334. These are in the second sector of the ZGREP.COM file.  You can 
  335. patch these to any sequence you like, but be sure to terminate 
  336. the string with a binary zero.
  337.  
  338. As distributed, ZGREP.COM is patched to display the control 
  339. characters with the carat prefix, '^', since this is the manner 
  340. of specifying them in the search expression.
  341.  
  342. 018B:     5E 00     (ASCII '^')
  343. 0192:     00        (nothing) 
  344.  
  345. But you could just as well use -
  346.  
  347. 018B:     5B 00     (ASCII '[')
  348. 0192:     5D 00     (ASCII ']')
  349.  
  350. The Kaypro 4 version could be set up as follows  -
  351.  
  352. 018B:     1B 42 30 1B 42 31 00     (Inverse and low-intensity ON)
  353. 0192:     1B 43 30 1B 43 31 00     (Inverse and low-intensity OFF)
  354.  
  355. When writing to a redirected file, control characters are 
  356. always displayed as, e.g. '^B' (with '^?' representing DEL), 
  357. regardless of the video attribute settings.
  358.  
  359. Try the following redirective -
  360.  
  361. A0>ZG "exp" file >CON:
  362.  
  363. You will see the '^' prefix used on the screen, even if you have 
  364. set video attributes for the screen.  This is because redirecting 
  365. the output to the screen (as CON:) opens a separate IO stream 
  366. which uses the default prefix '^' as if it were writing to a 
  367. file.
  368.  
  369. Further patching -
  370.  
  371. There are several more locations which may be patched using DDT, 
  372. EDFILE, etc.  (The following locations are shown as displayed by 
  373. DDT or EDFILE.  The actual locations in the .COM file are 0100H 
  374. less.)
  375.  
  376.      0199H     00H entry Query mode  [Q flag  01 = ON, 00 = OFF
  377.      019BH     00H entry Number mode [N flag
  378.      019DH     00H entry inVert mode [V flag
  379.      019FH     00H entry Formfeed    [F flag
  380.      01A1H     50H ('P') maximum drive letter, ASCII upper case.
  381.      01A3H     0FH (15)  maximum user number.
  382.      01A5H     64H (100) maximum number of files per filespec.
  383.      01A6H     00 - high order byte for maximum number of files.
  384.  
  385. Maximum drive is the highest drive letter that will be accepted 
  386. as valid in a filespec.  Maximum user number is similar, but also 
  387. sets the highest user number that will be searched if a wild user 
  388. spec, for example, A*:*.COM is given.  You may want to lower 
  389. the maximum user to speed up wild user searches, since the search 
  390. starts at user zero and goes up to and includes the maximum.  The 
  391. highest allowable maximum user is 31.
  392.  
  393. 9.   Aborting ZGREP
  394.  
  395. If you want to abort ZGREP , the most reliable way is to type ^C.  
  396. You will be prompted with the following message:
  397.  
  398.                     Abort? (Y/N)
  399.  
  400. A 'Y' answer will abort the session.
  401.  
  402.  
  403. 10.           Special operations on ASCII files
  404.  
  405. These applications are accomplished by trying to match only the 
  406. end of a line ('$' - which never matches), and then displaying 
  407. the non-matching lines using the [v flag, thus getting all the 
  408. lines in the file.
  409.  
  410.  
  411.             Wildcard TYPE
  412.  
  413. ZG $ [v file1.txt file2.doc *.not
  414.  
  415. will type all the files to the console in order.  Use control-S 
  416. to pause the display at any time.
  417.  
  418.  
  419.             File Copying
  420.  
  421. A0:ZG $ [v TEXT.FIL >B:TEXT.CPY
  422.  
  423. will copy TEXT.FIL to B0:TEXT.CPY
  424.  
  425. Warning: if you try to copy a file to the same drive, user area 
  426. and file name, it will be destroyed.
  427.  
  428.  
  429.             Line numbering
  430.  
  431. ZG $ [vn TEXT.FIL >TEXT.NUM
  432.  
  433. will create a copy of TEXT.FIL called TEXT.NUM which has line 
  434. numbers preceding each line of text.
  435.  
  436.  
  437.             Concatenating
  438.  
  439. ZG $ [v file1 file2 file3 >file123
  440.  
  441. will concatenate the three files into file123.
  442.  
  443.  
  444.               Listing
  445.  
  446. ZG $ [vf file? >lst:
  447.  
  448. will send file1, file2, and file3 to the printer in that order, 
  449. with a formfeed after each file.
  450.  
  451.  
  452.               Filtering
  453.  
  454. ZG $ [v WORDSTAR.DOC >ASCII.TXT
  455.  
  456. will convert a WordStar file to an ASCII file by zeroing all the 
  457. 8th bits, and displaying all control chars with the '^' prefix.
  458.  
  459.