home *** CD-ROM | disk | FTP | other *** search
- GREP.DOC
- Similarity to GREP001
- _____________________
-
- This program is similar to GREP001. The differences are that GREP001 does
- not allow re-direction of output and if wildcards are used in the file list,
- only the first matching directory entry will be scanned. Finally, GREP
- uses ":_" to match whitespace while GREP001 uses ": ". This last change was
- made because I use it with MicroShell which treats space as end of argument
- even within a quoted string.
-
- The source code
- ---------------
- The source code in GREP.C is set-up for use with MicroShell
- which does directed output for ANY executable program which sends output to
- the console. Un-commenting the "#include dio.h" and commenting out the
- "#define MICROSHELL" are the only changes necessary to build the executable
- version on this RBBS.
-
- Associated files
- ----------------
-
- Associated files: GREP.C, GREP.OBJ, GREP.DOC. To re-build it, first you need
- BDS-C. Then:
-
- cc grep.c -o -e 4700
- cc dio.c
- l2 grep dio
-
- Note that "dio.c", and "l2.com" both come with BDS C. To just use it, read on.
-
- Directed output, wildcards, file matching limitations
- -----------------------------------------------------
- GREP works as described below and includes the ability to re-direct
- output to a file or to send output both to the console and to a file. The
- file list may include drive specifiers but not (as yet) user numbers. It may
- also include wildcards. Grep does not (yet) work on SQueezed files.
-
- The files identified by each individual wildcard specification will be
- accessed in alphabetical order rather than the arbitrary order in which they
- appear in the directory. Some examples of invocation are:
-
- EXAMPLES of INVOCATION
- ----------------------
-
- Print to the console each LINE of each file in "A:X???????.ASM" and
- "B:Y???????.ASM" and "C:????????.ASM" which contains an identifier immediately
- followed by a colon left justified on the line. Identifier in this context is
- defined as (starts with an alpha followed by zero or more alphamerics. For
- each file which contains at least one matching line, the file name and the
- match pattern will be printed prior to printing the matching lines.
-
- grep "^:a:d*\:" a:x*.asm b:y*.asm c:*.asm
-
- -------------------------------------------------------------------------------
- Do the same thing but print the results on file "F:IDENTITY.XXX"
-
- grep "^:a:d*\:" a:x*.asm b:y*.asm c:*.asm >identity.xxx
-
- -------------------------------------------------------------------------------
- Print all lines in the file "YECH.ICH" which contain a parenthesisized
- expression. Print the results both on the console and on file "UGH.X".
-
- grep "(.*)" yech.ich +ugh.x
-
- -------------------------------------------------------------------------------
- Print all lines in files matching "????????.C" which contain
- "variableofinterest" on the console. Number the lines according to their
- position in the file.
-
- grep -n variableofinterest *.c
-
- -------------------------------------------------------------------------------
- MANY more things are possible. Read the description below and experiment a
- bit. You will find very quickly that there is no way you could have been
- living without GREP all these years.
-
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Description of OPTIONS and PATTERN MATCH Possibilities
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- Invoke as:
- grep ?
- to reprint the following description. Note: [] surround optional items.
-
-
- grep searches a file list for a given pattern. Execute by:
-
- grep [flags] regular_expression file_list [>outfile OR +outfile]
-
- Flags are single characters preceeded by '-':
-
- -c Only a count of matching lines is printed
- -f Print file name for matching lines switch, see below
- -n Each line is preceeded by its line number
- -v Only print non-matching lines
-
- The file_list is a list of files (wildcards are acceptable).
- If no files are given, input comes from the terminal. There is no prompting.
- The file name is normally printed if there is a file given.
- The -f flag reverses this action (print name no file, not if more).
-
- The regular_expression defines the pattern to search for. Upper- and
- lower-case are always ignored. Blank lines never match. The expression
- should be quoted to make it a single argument.
-
- x An ordinary character (not mentioned below) matches that character.
- \ The backslash quotes any character. "\$" matches a dollar-sign.
- ^ A circumflex at the beginning of an expression
- matches the beginning of a line.
- $ A dollar-sign at the end of an expression matches the end of a line.
- . A period matches any character except "new-line".
-
- : A colon matches a class of characters described below
-
- ":a" matches any alphabetic
- ":d" matches digits,
- ":n" matches alphanumerics
- ":_" matches spaces, tabs, and
- other control characters, such as new-line.
- * An expression followed by an asterisk matches zero or
- more occurrances of that expression:
-
- "fo*" matches "f", "fo" "foo", etc.
-
- + An expression followed by a plus sign matches one
- or more occurrances of that expression:
-
- "fo+" matches "fo", etc.
-
- - An expression followed by a minus sign optionally
- matches the expression.
- [] A string enclosed in square brackets matches any
- character in that string, but no others.
-
- If the first character in the string is a circumflex,
- the expression matches any character except "new-line"
- and the characters in the string. For example, "[xyz]"
- matches "xx" and "zyx", while "[^xyz]" matches "abc" but not "axb".
- A range of characters may be specified by two characters
- seperated by "-". Note that, [a-z] matches alphabetics, while
- [z-a] never matches.
-
- The concatenation of regular expressions is a regular expression.
- s digits,
- ":n" matches alphanumeri