The nismatch and nisgrep commands search through NIS+ tables for entries that match a particular string or regular expression, respectively. They display either the entries themselves or a count of how many entries matched. The differences between the nismatch and nisgrep commands are highlighted in Table 19–6 below.
Table 19–6 Characteristics of nismatch and nisgrep
Characteristics |
nismatch |
nisgrep |
---|---|---|
Search criteria |
Accepts text only |
Accepts regular expressions |
Speed |
Faster |
Slower |
Searches through |
Searchable columns only |
All columns, whether searchable or not |
Syntax of search criteria |
column=string ... tablename[ column= string,...], tablename |
column=exp ... tablename |
The tasks and examples in this section describe the syntax for both commands.
To use either command, you must have read access to the table you are searching through.
The examples in this section are based on the values in the following table, named depts.doc.com. Only the first two columns are searchable.
Name (S) |
Site (S) |
Name |
---|---|---|
R&D |
SanFran |
kuznetsov |
Sales |
SanFran |
jhill |
Manf-1 |
Emeryville |
hosteen |
Manf-2 |
Sausalito |
lincoln |
Shipping-1 |
Emeryville |
tsosulu |
Shipping-2 |
Sausalito |
katabami |
Service |
Sparks |
franklin |
Regular expressions are combinations of text and symbols that you can use to search for special configurations of column values. For example, the regular expression `Hello' searches for a value that begins with Hello. When using a regular expression in the command line, be sure to enclose it in quotes, since many of the regular expression symbols have special meaning to the Bourne and C shells. For example:
rootmaster% nisgrep -h greeting='Hello' phrases.doc.com. |
The regular expression symbols are summarized in Table 19–7, below.
Table 19–7 Regular Expression Symbols
Symbol |
Description |
---|---|
^string |
Find a value that begins with string. |
string $ |
Find a value that ends with string. |
. |
Find a value that has a number characters equal to the number of periods. |
[chars] |
Find a value that contains any of the characters in the brackets. |
*expr |
Find a value that has zero or more matches of the expr. |
+ |
Find something that appears one or more times. |
? |
Find any value. |
\'s-char' |
Find a special character, such as ? or $. |
x | y |
Find a character that is either x or y. |
To search through the first column, use:
nismatch string tablename nisgrep reg-exp tablename |
To search through a particular column, use:
nismatch column=string tablename nisgrep column=reg-exp tablename |
To search through multiple columns, use:
nismatch column=string tablename ...\ nismatch [column=string,...],tablename nisgrep column=reg-exp ... \ tablename |
Option |
Description |
---|---|
-c |
Count. Instead of the entries themselves, displays a count of the entries that matched the search criteria. |
-h |
Header. Displays a header line above the entries, listing the name of each column. |
-M |
Master. Displays only the entries of the table stored on the master server. This ensures you get the most up-to-date information and should be used only for debugging. |
To search for a particular value in the first column of a table, simply enter the first column value and a tablename. In nismatch, the value must be a string. In nisgrep, the value must be a regular expression.
nismatch [-h] string tablename nisgrep [-h] reg-expression tablename |
This example searches through the depts table for all the entries whose first column has a value of R&D:
rootmaster% nismatch -h `R&D' depts.doc.com. rootmaster% nisgrep -h `R&D' depts.doc.com. |
Quotes are used in the 'R&D' expression above to prevent the shell from interpreting the ampersand (&) as a metacharacter.
To search through a particular column other than the first, use the following syntax:
nismatch column=string tablename nisgrep column=reg-expression tablename |
This example searches through the depts table for all the entries whose second column has a value of SanFran:
rootmaster% nismatch -h Site=SanFran depts.doc.com. rootmaster% nisgrep -h Site=SanFran depts.doc.com. |
To search for entries with matches in two or more columns, use the following syntax:
nismatch [-h] [column=string, ... \ column=string,...],tablename nisgrep [-h] column=reg-exp ... \ tablename |
This example searches for entries whose second column has a value of SanFran and whose third column has a value of jhill:
rootmaster% nismatch -h [Site=SanFran,Name=jhill], depts.doc.com. rootmaster% nisgrep -h Site=SanFran Name=jhill depts.doc.com. |