home *** CD-ROM | disk | FTP | other *** search
/ CBM Funet Archive / cbm-funet-archive-2003.iso / cbm / c128 / os / cs-dos / cs-grep.sfx / grep.txt < prev    next >
Encoding:
Text File  |  1990-02-02  |  6.6 KB  |  2 lines

  1.  
  2. Function:   GREP
  3.  
  4. Usage:      GREP [-options] RegularExpression File(s)
  5.  
  6.     Grep is something you've probably come across before. It scans a list of
  7. text files for lines containing a specified pattern and displays any matching
  8. lines. This implementation is essentially the same as what you'd come accross
  9. in an MS-DOS, CP/M, AmigaDOS or UNIX implementation, and was derived from the
  10. original 1980 DECUS source code. Since that source code is in the public
  11. domain, so is this implementation of it. That source can be found in a number
  12. of places, including disk #314 of the PC-SIG collection.
  13.  
  14.     This implementation uses services provided by CS-DOS on the Commodore 128
  15. and will not work without it. You must have CS-DOS loaded and active or this
  16. will not work.
  17.  
  18.     Grep expects to be processing text files. If you run it on programs or
  19. other binary files the screen will likely get garbled the same as if you had
  20. TYPE'd the file. Grep can still supply some useful information though, but
  21. you should use -c to suppress output.
  22.  
  23.  
  24. Options are:
  25.  
  26.     -c   -  Grep will display only a count of the number of matches, and does
  27.             not display the lines containing the specified pattern.
  28.  
  29.     -f   -  If you specify -f then filenames are not shown. Normally they are
  30.             shown.
  31.  
  32.     -n   -  Grep will print line numbers of matching lines to the left of the
  33.             line. Normally it doesn't.
  34.  
  35.     -v   -  Grep shows only lines that don't contain the specified pattern.
  36.  
  37.     -y   -  Normally alphabetic characters are case sensitive. With -y case
  38.             is ignored. ( [a-z] is the same as [A-Z] )
  39.  
  40. Regular Expressions:
  41.  
  42.     Regular expressions similar to the * and ? characters used in specifying
  43. filenames to CBM's DOS. If you havn't come accross them before, its worth the
  44. effort of getting aquainted with them because they keep popping up here and
  45. there in various programs that you'll likely come accross in the future.
  46.     Just as * and ? are 'special' characters in CBM filenames, regular
  47. expressions contain a number of special characters. I'll just list them off
  48. and give a bunch of examples later to illustrate thier usage.
  49.  
  50.  
  51.     \    -  The backslash (or the british pound sign on the CBM keyboard)
  52.             is used to override the special meaning of a character. Thus
  53.  
  54.             \\          - matches a backslash
  55.             \.          - matches a period
  56.  
  57.     .    -  The period is the wildcard character in regular expresions. It
  58.             matches any character. For example:
  59.  
  60.             b.b         - matches bob, bub bbb and so on.
  61.  
  62.     ^    -  The circumflex (or up arrow on the CBM keyboard) matches the
  63.             start of a line.
  64.  
  65.             ^;          - matches all lines that start with a semi-colon
  66.  
  67.     $    -  The dollar sign matches the end of a line.
  68.  
  69.             ,x)$        - matches all lines that end with ",x)"
  70.  
  71.     []   -  A list of characters within square brackets (a class) matches
  72.             any of the characters in the class.
  73.  
  74.             ld[axy]     - matches lda, ldx or ldy
  75.  
  76.     [^]  -  Preceding the list with a circumflex matches anything except
  77.             characters in the class.
  78.  
  79.             ^[; ]       - matches all lines which do not start with either
  80.                           a semicolon or a space.
  81.  
  82.     [a-z]   Specifies a range of characters.
  83.  
  84.             [a-z][0-9]= - matches a0= b1= c3= and so on
  85.  
  86.     *    -  A character followed by an asterisk matches zero or more ocurrences
  87.             of that character.
  88.  
  89.             a*          - matches a, aa, aaa, and so on
  90.             a*[0-9]*    - matches 9, a89, aaaa1234 and so on
  91.  
  92.     +    -  A character followed by a plus sign matches one or more
  93.             occurences of that character. x+ is the same as xx*
  94.  
  95.             a+b+c       - matches abc, aabbcc, but not ac or bc
  96.             a+[0-9]*    - matches a89, aaaa1234 but not 9
  97.  
  98.     -    -  A character followed by a - optionally matches that character.
  99.  
  100.             a-b-c       - matches ac or bc or c
  101.             if:b(       - matches "if ("
  102.             if:b-(      - matches "if (" or "if("
  103.           
  104.  
  105. Predefined classes:
  106.  
  107.     As an alternative to using [a-z], [0-9] and so on, some classes are
  108.     predefined.
  109.  
  110.     :a   -  shorthand for [a-zA-Z]      (alpha)
  111.     :b   -  Matches any whitespace      (spaces, tabs or newlines)
  112.     :       (colon space) same as :b
  113.     :d   -  shorthand for [0-9]         (digit)
  114.     :n   -  shorthand for [a-zA-Z0-9]   (alphanumeric)
  115.     :q   -  shorthand for ['"]          (avoids command line parsing problems)
  116.     :x   -  shorthand for [0-9a-fA-F]   (hexadecimal digit)
  117.  
  118. Notes:
  119.  
  120.     Blank lines are ignored, so they can never match.
  121.  
  122.     Expressions that contain spaces or commas should be enclosed in quotes.
  123.     For example
  124.  
  125.     grep "if (" file    - Searches one file named "file" for occurrences of
  126.                           "if (", but
  127.  
  128.     grep if ( file      - Searches two files named "(" and "file" for
  129.                           occurrences of "if"
  130.  
  131.     Two versions of GREP are provided. Both are functionally equivalent. You
  132.     should choose the one you want, rename it to "GREP" and discard the other
  133.     one.
  134.  
  135.     GREP1 is compiled to run in bank 1 at $4000. This has the advantage of
  136.     leaving your text area alone in bank 0, so if you're editing
  137.     a BASIC program GREP won't LOAD in overtop of it. You must use
  138.  
  139.         INSTALL/1 grep
  140.  
  141.     to install GREP in the RAM disk. Since CS-DOS always loads programs
  142.     from disk into bank 15, you can't execute GREP1 from floppy.
  143.  
  144.     GREP0 is compiled to run in bank 15 at $1c01. This means that it
  145.     will clobber any BASIC program being edited. However they can be run
  146.     from floppy, so if you want run GREP on floppy rather than the RAM disk,
  147.     you'll need to use this one.
  148.  
  149.  
  150.     GREP will not work with CS-DOS 1.1, it requires 1.4 or higher.
  151.  
  152. Examples:
  153.  
  154.  
  155.     grep for file1 file2
  156.  
  157.         Searches "file1" and "file2" for lines containing the string "for",
  158.         "FOR", "For", "FoR" and so on.
  159.  
  160.     grep for file1 file2 -y
  161.  
  162.         Same but matches only "for"
  163.  
  164.     grep -c :q.*:q *.asm
  165.  
  166.         Searches all files whose name ends with ".asm" for any lines containing
  167.         quoted strings; Either 'single' or "double" quotes, and shows only the
  168.         number of lines matched for each file.
  169.  
  170.     grep #\$:x+[:b;] g*.asm b*.asm
  171.  
  172.         Searches all files starting with "g" or "b" and ending with ".asm" for
  173.         "#$" followed by a hexadecimal number followed by either a newline, a
  174.         semicolon or whitespace.
  175.  
  176.     grep :a+:n*\$ text.bas
  177.  
  178.         Searches "text.bas" for what would be a legal BASIC string variable
  179.         name.
  180.  
  181.  
  182.  
  183.