home *** CD-ROM | disk | FTP | other *** search
-
- Function: GREP
-
- Usage: GREP [-options] RegularExpression File(s)
-
- Grep is something you've probably come across before. It scans a list of
- text files for lines containing a specified pattern and displays any matching
- lines. This implementation is essentially the same as what you'd come accross
- in an MS-DOS, CP/M, AmigaDOS or UNIX implementation, and was derived from the
- original 1980 DECUS source code. Since that source code is in the public
- domain, so is this implementation of it. That source can be found in a number
- of places, including disk #314 of the PC-SIG collection.
-
- This implementation uses services provided by CS-DOS on the Commodore 128
- and will not work without it. You must have CS-DOS loaded and active or this
- will not work.
-
- Grep expects to be processing text files. If you run it on programs or
- other binary files the screen will likely get garbled the same as if you had
- TYPE'd the file. Grep can still supply some useful information though, but
- you should use -c to suppress output.
-
-
- Options are:
-
- -c - Grep will display only a count of the number of matches, and does
- not display the lines containing the specified pattern.
-
- -f - If you specify -f then filenames are not shown. Normally they are
- shown.
-
- -n - Grep will print line numbers of matching lines to the left of the
- line. Normally it doesn't.
-
- -v - Grep shows only lines that don't contain the specified pattern.
-
- -y - Normally alphabetic characters are case sensitive. With -y case
- is ignored. ( [a-z] is the same as [A-Z] )
-
- Regular Expressions:
-
- Regular expressions similar to the * and ? characters used in specifying
- filenames to CBM's DOS. If you havn't come accross them before, its worth the
- effort of getting aquainted with them because they keep popping up here and
- there in various programs that you'll likely come accross in the future.
- Just as * and ? are 'special' characters in CBM filenames, regular
- expressions contain a number of special characters. I'll just list them off
- and give a bunch of examples later to illustrate thier usage.
-
-
- \ - The backslash (or the british pound sign on the CBM keyboard)
- is used to override the special meaning of a character. Thus
-
- \\ - matches a backslash
- \. - matches a period
-
- . - The period is the wildcard character in regular expresions. It
- matches any character. For example:
-
- b.b - matches bob, bub bbb and so on.
-
- ^ - The circumflex (or up arrow on the CBM keyboard) matches the
- start of a line.
-
- ^; - matches all lines that start with a semi-colon
-
- $ - The dollar sign matches the end of a line.
-
- ,x)$ - matches all lines that end with ",x)"
-
- [] - A list of characters within square brackets (a class) matches
- any of the characters in the class.
-
- ld[axy] - matches lda, ldx or ldy
-
- [^] - Preceding the list with a circumflex matches anything except
- characters in the class.
-
- ^[; ] - matches all lines which do not start with either
- a semicolon or a space.
-
- [a-z] Specifies a range of characters.
-
- [a-z][0-9]= - matches a0= b1= c3= and so on
-
- * - A character followed by an asterisk matches zero or more ocurrences
- of that character.
-
- a* - matches a, aa, aaa, and so on
- a*[0-9]* - matches 9, a89, aaaa1234 and so on
-
- + - A character followed by a plus sign matches one or more
- occurences of that character. x+ is the same as xx*
-
- a+b+c - matches abc, aabbcc, but not ac or bc
- a+[0-9]* - matches a89, aaaa1234 but not 9
-
- - - A character followed by a - optionally matches that character.
-
- a-b-c - matches ac or bc or c
- if:b( - matches "if ("
- if:b-( - matches "if (" or "if("
-
-
- Predefined classes:
-
- As an alternative to using [a-z], [0-9] and so on, some classes are
- predefined.
-
- :a - shorthand for [a-zA-Z] (alpha)
- :b - Matches any whitespace (spaces, tabs or newlines)
- : (colon space) same as :b
- :d - shorthand for [0-9] (digit)
- :n - shorthand for [a-zA-Z0-9] (alphanumeric)
- :q - shorthand for ['"] (avoids command line parsing problems)
- :x - shorthand for [0-9a-fA-F] (hexadecimal digit)
-
- Notes:
-
- Blank lines are ignored, so they can never match.
-
- Expressions that contain spaces or commas should be enclosed in quotes.
- For example
-
- grep "if (" file - Searches one file named "file" for occurrences of
- "if (", but
-
- grep if ( file - Searches two files named "(" and "file" for
- occurrences of "if"
-
- Two versions of GREP are provided. Both are functionally equivalent. You
- should choose the one you want, rename it to "GREP" and discard the other
- one.
-
- GREP1 is compiled to run in bank 1 at $4000. This has the advantage of
- leaving your text area alone in bank 0, so if you're editing
- a BASIC program GREP won't LOAD in overtop of it. You must use
-
- INSTALL/1 grep
-
- to install GREP in the RAM disk. Since CS-DOS always loads programs
- from disk into bank 15, you can't execute GREP1 from floppy.
-
- GREP0 is compiled to run in bank 15 at $1c01. This means that it
- will clobber any BASIC program being edited. However they can be run
- from floppy, so if you want run GREP on floppy rather than the RAM disk,
- you'll need to use this one.
-
-
- GREP will not work with CS-DOS 1.1, it requires 1.4 or higher.
-
- Examples:
-
-
- grep for file1 file2
-
- Searches "file1" and "file2" for lines containing the string "for",
- "FOR", "For", "FoR" and so on.
-
- grep for file1 file2 -y
-
- Same but matches only "for"
-
- grep -c :q.*:q *.asm
-
- Searches all files whose name ends with ".asm" for any lines containing
- quoted strings; Either 'single' or "double" quotes, and shows only the
- number of lines matched for each file.
-
- grep #\$:x+[:b;] g*.asm b*.asm
-
- Searches all files starting with "g" or "b" and ending with ".asm" for
- "#$" followed by a hexadecimal number followed by either a newline, a
- semicolon or whitespace.
-
- grep :a+:n*\$ text.bas
-
- Searches "text.bas" for what would be a legal BASIC string variable
- name.
-
-
-
-