|Skip Navigation Links|
|Exit Print View|
|System Administration Guide: Naming and Directory Services (NIS+)|
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
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.
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 in NIS+
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
Table 19-8 nismatch and nisgrep Options
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.
Note - 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.