GrepDoc.tioga
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) May 14, 1986 5:04:10 pm PDT
Donahue, July 16, 1985 8:46:45 am PDT
Tim Diebert: December 31, 1985 9:03:37 am PST
GREP
CEDAR 6.1 — FOR INTERNAL XEROX USE ONLY
Grep
-- a pattern-scanning program
Russ Atkinson
© Copyright 1985, 1986 Xerox Corporation. All rights reserved.
Abstract: Grep will search a list of files for lines that match a pattern and print the lines that match the given regular expression (see RegularExpressionDoc.tioga for a description of the syntax for a regular expression).
Created by: Bob Nix (after Unix)
Maintained by: Russ Atkinson <Atkinson.pa>
Keywords: searching
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
Syntax
grep [switches] pattern fileNames
Overview
Grep will search a list of files for lines that match a pattern and print the lines that match the given regular expression (see RegularExpressionDoc.tioga for a description of the syntax for a regular expression). A line is defined to be a sequence of characters terminated by a newline or end of file. If no file names are given, then grep reads from its standard input.
By default, grep's output looks something like this:
% grep Dorado *Doc.tioga
[]<>AlpineDoc.tioga!1
(535): ...he server runs on a Dorado named Bataan, whose ter...
[]<>SafeStoragePrimerDoc.tioga!1
(8032): ... half a minute on a Dorado to do its work. The Tra...
[]<>SpellingToolDoc.tioga!1
(16451): ...rds per second on a Dorado, and while one could pr...
[]<>WalnutDoc.Tioga!1
(18392): ...If you use a public Dorado, it is strongly urged t...
[]<>WalnutOnAlpineDoc.tioga!1
(2926): ...a Dolphin, two on a Dorado.
(17072): ...a Dolphin, two on a Dorado.
(19859): ... Walnut on a public Dorado, you probably have some...
(32588): ...a Dolphin, two on a Dorado.
(35315): ... Walnut on a public Dorado, you probably have some...
Files examined: 24, files matched: 5, number of matches: 9
%
The output is divided into sections, one for each file that contains at least one line that matches the pattern. The first line of the section gives the name of the file, and each succeeding indented line describes a matching location by giving the character position (the number in parenthesis) of the match and then showing a few characters to either side of the point of the match.
Switches
Grep accepts lots of switches (-p, -c, and -w are the interesting ones):
-binaryFilesToo (-b)
Grep tries to avoid scanning non-text files by skipping any file whose full name contains the substrings .bcd, .press, .symbols, .ip, .interpress, .tipc, .boot, .versionmap, or .bittable. To force grep to scan such files, invoke grep with the -binaryFilesToo switch.
-caseSensitive (-c)
By default, grep ignores capitalization differences between the pattern and the text examined. This switch will make such differences important. For example, ``grep pringle *.chips'' will match a line containing the word ``Pringle'', but ``grep -c pringle *.chips'' will not.
-fileNamesOnly (-f)
Print only the names of the files that contain at least one match.
-ignoreTiogaFormatting (-i)
This switch causes grep to ignore all tioga formatting information, including comment nodes.
-oncePerLine (-o)
Grep will print a matching line exactly once, even if the pattern matches at several places in the line.
-pattern (-p)
By default, grep's pattern argument is taken to be a literal string, i.e. all special characters in the pattern are implicitly quoted. If the -pattern switch is given, then the pattern is interpreted relative to the regular expression syntax described in RegularExpressionDoc.tioga. For example, ``grep (this|that) *.tioga'' will search for occurrences of the string ``(this|that)'', whereas ``grep -p (this|that) *.tioga'' will find all lines that contain the string ``this'' or the string ``that''.
-positionsOnly (-po)
Print only the file names and positions of each match.
-stopOnFirstError (-s)
If this switch is given, then grep will stop grepping when it encounters its first error, e.g. if ``grep PROC [Indigo]<Cedar>*.mesa'' is unable to open some file, it will stop. By default it would go on to try the next file.
-textOnly (-t)
Don't give the file names or positions, just the full text of the line containing each match.
-verbose (-v)
Like the standard output format, except that grep mentions the name of every file that it searches (even the ones that don't contain a match) and it prints the full line containing each match.
-word (-w)
The matching text must not have adjacent letters or digits.
Etymology
In the prehistoric Unix editor ed, the command that found all of the lines that matched a regular expression (r.e.) and printed them was ``g/r.e./p''.
Examples
% grep error *Impl.mesa
% grep -word -c ERROR *Impl.mesa
% grep -pat [aeiou][aeiou][aeiou][aeiou] < /Indigo/SpellingToolData/web2.dic
Bugs
Tioga's Position command behaves a bit mysteriously, and so it might not get you exactly to the place where the match occurred.
Grep knows nothing about Tioga formatting (except how to ignore it if you want it to). This decision was made deliberately in order to make the scanning more efficient.
Programmer's Interface
Grep.mesa includes procedures to read switch settings from a command line and to perform a Grep on a given input stream, writing the result on a given output stream.