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.
-enumerateCache (-e)
Enumerate only files in the local cache, with remoteCheck = FALSE. If the files in your cache are up to date (from a recent Grep, for example), you can use this switch to avoid traffic with a remote server. This switch is not available in PCedar.
-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.
-locations (-l)
Print only the file names and positions of each match.
-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''.
-quiet (-q)
If this switch is given, then grep will not print out its end of program summation of the number of files found and the number of matches found.
-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.
-xcept (-x)
Prints lines except those that match pattern.