Previous Section  < Day Day Up >  Next Section

rgrep—a recursive, highlighting grep program


rgrep [ options] pattern [file] ......


rgrep, unlike grep and egrep, can recursively descend directories. The traditional way of performing this kind of search on UNIX systems utilizes the find command in conjunction with grep. Using rgrep results in much better performance. See also xargs command.

COMMAND-LINE OPTIONS:

-?

Additional help (use -? to avoid shell expansion on some systems).

-c

Count matches.

-h

Highlight match (ANSI-compatible terminal assumed).

-H

Output match instead of entire line containing match.

-i

Ignore case.

-l

List filename only.

-n

Print line number of match.

-F

Follow links.

-r

Recursively scan through directory tree.

-N

Do NOT perform a recursive search.

-R pat

Like -r except that only those files matching pat are checked.

-v

Print only lines that do NOT match the specified pattern.

-x ext

Check only files with extension given by ext.

-D

Print all directories that would be searched. This option is for debugging purposes only. No file is grepped with this option.

-W len

Lines are len characters long (not newline terminated).


SUPPORTED REGULAR EXPRESSIONS:

.

Matches any character except newline.

\d

Matches any digit.

\e

Matches ESC char.

*

Matches zero or more occurrences of previous RE.

+

Matches one or more occurrences of previous RE.

?

Matches zero or one occurrence of previous RE.

^

Matches beginning of line.

$

Matches end of line.

[ ... ]

Matches any single character between brackets. For example, [-02468] matches - or any even digit, and [-0-9a-z] matches - and any digit between 0 and 9 as well as letters a through z.

\{ ...\}

Used for repetition; e.g., x\{9\} matches nine x characters

\( ...\)

Used for backreferencing. Pattern in \(...\) is tagged and saved. Starting at the left-hand side of the regular expression, allowed up to nine tags. To restore saved pattern, \1, \2 ... \9 are used.

\2 \1, =, ...., \9

Matches match specified by nth \( ... \) expression. For example, \([ \t][a-zA-Z]+\)\1[ \t] matches any word repeated consecutively.


Example A.45.

1   rgrep -n -R '*.c' '^int'

2   rgrep -n -xc '^int'


EXPLANATION

  1. Look in all files with a "c" extension in current directory and all its subdirectories looking for matches of "int" at the beginning of a line, printing the line containing the match with its line number.

  2. Look in all files with a ".c" extension, printing the line beginning with "int" and preceded with its line number. (Same as above.)

    Previous Section  < Day Day Up >  Next Section