home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / f / grep2.lbr / GREP.DZC / GREP.DOC
Encoding:
Text File  |  1993-10-26  |  6.0 KB  |  148 lines

  1. GREP.DOC
  2.         Similarity to GREP001
  3.         _____________________
  4.  
  5.   This program is similar to GREP001.  The differences are that GREP001 does
  6. not allow re-direction of output and if wildcards are used in the file list,
  7. only the first matching directory entry will be scanned.  Finally, GREP
  8. uses ":_" to match whitespace while GREP001 uses ": ".  This last change was
  9. made because I use it with MicroShell which treats space as end of argument
  10. even within a quoted string.
  11.  
  12.         The source code
  13.         ---------------
  14.   The source code in GREP.C is set-up for use with MicroShell
  15. which does directed output for ANY executable program which sends output to
  16. the console.  Un-commenting the "#include dio.h" and commenting out the
  17. "#define MICROSHELL" are the only changes necessary to build the executable
  18. version on this RBBS.
  19.  
  20.         Associated files
  21.         ----------------
  22.  
  23.   Associated files: GREP.C, GREP.OBJ, GREP.DOC.  To re-build it, first you need
  24. BDS-C. Then:
  25.  
  26.     cc grep.c -o -e 4700
  27.     cc dio.c
  28.     l2 grep dio
  29.  
  30. Note that "dio.c", and "l2.com" both come with BDS C.  To just use it, read on.
  31.  
  32.     Directed output, wildcards, file matching limitations
  33.     -----------------------------------------------------
  34.   GREP works as described below and includes the ability to re-direct
  35. output to a file or to send output both to the console and to a file.  The
  36. file list may include drive specifiers but not (as yet) user numbers. It may
  37. also include wildcards.   Grep does not (yet) work on SQueezed files.
  38.  
  39.   The files identified by each individual wildcard specification will be
  40. accessed in alphabetical order rather than the arbitrary order in which they
  41. appear in the directory.  Some examples of invocation are:
  42.  
  43.         EXAMPLES of INVOCATION
  44.         ----------------------
  45.  
  46.   Print to the console each LINE of each file in "A:X???????.ASM" and
  47. "B:Y???????.ASM" and "C:????????.ASM" which contains an identifier immediately
  48. followed by a colon left justified on the line.  Identifier in this context is
  49. defined as (starts with an alpha followed by zero or more alphamerics.  For
  50. each file which contains at least one matching line, the file name and the
  51. match pattern will be printed prior to printing the matching lines.
  52.  
  53.     grep "^:a:d*\:" a:x*.asm b:y*.asm c:*.asm
  54.  
  55. -------------------------------------------------------------------------------
  56.   Do the same thing but print the results on file "F:IDENTITY.XXX"
  57.  
  58.     grep "^:a:d*\:" a:x*.asm b:y*.asm c:*.asm >identity.xxx
  59.  
  60. -------------------------------------------------------------------------------
  61.   Print all lines in the file "YECH.ICH" which contain a parenthesisized
  62. expression.  Print the results both on the console and on file "UGH.X".
  63.  
  64.     grep "(.*)" yech.ich +ugh.x
  65.  
  66. -------------------------------------------------------------------------------
  67.   Print all lines in files matching "????????.C" which contain
  68. "variableofinterest" on the console.  Number the lines according to their
  69. position in the file.
  70.  
  71.     grep -n variableofinterest *.c
  72.  
  73. -------------------------------------------------------------------------------
  74.   MANY more things are possible.  Read the description below and experiment a
  75. bit.  You will find very quickly that there is no way you could have been
  76. living without GREP all these years.
  77.  
  78. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  79. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  80.     Description of OPTIONS and PATTERN MATCH Possibilities
  81. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  82. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  83.  
  84. Invoke as:
  85.     grep ?
  86. to reprint the following description. Note: [] surround optional items.
  87.  
  88.  
  89. grep searches a file list for a given pattern.  Execute by:
  90.  
  91.     grep [flags] regular_expression file_list [>outfile OR +outfile]
  92.  
  93. Flags are single characters preceeded by '-':
  94.  
  95.     -c    Only a count of matching lines is printed
  96.     -f    Print file name for matching lines switch, see below
  97.     -n    Each line is preceeded by its line number
  98.     -v    Only print non-matching lines
  99.  
  100. The file_list is a list of files (wildcards are acceptable).
  101. If no files are given, input comes from the terminal.  There is no prompting.
  102. The file name is normally printed if there is a file given.
  103. The -f flag reverses this action (print name no file, not if more).
  104.  
  105. The regular_expression defines the pattern to search for.  Upper- and
  106. lower-case are always ignored.  Blank lines never match.  The expression
  107. should be quoted to make it a single argument.
  108.  
  109. x    An ordinary character (not mentioned below) matches that character.
  110. \    The backslash quotes any character.  "\$" matches a dollar-sign.
  111. ^    A circumflex at the beginning of an expression
  112.     matches the beginning of a line.
  113. $    A dollar-sign at the end of an expression matches the end of a line.
  114. .    A period matches any character except "new-line".
  115.  
  116. :    A colon matches a class of characters described below
  117.  
  118.         ":a"    matches any alphabetic
  119.         ":d"    matches digits,
  120.         ":n"    matches alphanumerics
  121.         ":_"    matches spaces, tabs, and
  122.             other control characters, such as new-line.
  123. *    An expression followed by an asterisk matches zero or
  124.     more occurrances of that expression:
  125.  
  126.         "fo*" matches "f", "fo" "foo", etc.
  127.  
  128. +    An expression followed by a plus sign matches one
  129.     or more occurrances of that expression:
  130.  
  131.         "fo+" matches "fo", etc.
  132.  
  133. -    An expression followed by a minus sign optionally
  134.     matches the expression.
  135. []    A string enclosed in square brackets matches any
  136.     character in that string, but no others.
  137.  
  138.     If the first character in the string is a circumflex,
  139.     the expression matches any character except "new-line"
  140.     and the characters in the string.  For example, "[xyz]"
  141.     matches "xx" and "zyx", while "[^xyz]" matches "abc" but not "axb".
  142.     A range of characters may be specified by two characters
  143.     seperated by "-".  Note that, [a-z] matches alphabetics, while
  144.     [z-a] never matches.
  145.  
  146. The concatenation of regular expressions is a regular expression.
  147. s digits,
  148.         ":n"    matches alphanumeri