Wednesday, June 29, 2005

grep command

rep, egrep, fgrep
search a file for a pattern


grep [ -bchilnsvw ] limited-regular-expression [filename ... ]

egrep [-bchilnsvx] ... [file ...]

fgrep [-bchilnsv] ... [file ...]


The grep family searches text files for a pattern and prints all lines
that contain that pattern. Be careful using the characters $, *, [, ^,
|, (, ), and \ in the pattern_list because they are also meaningful to
the shell. It is safest to enclose the entire pattern_list in single
quotes '... '.

grep - uses a limited set of regular expressions

fgrep - fast grep, searches for a string not a pattern

egrep - expression grep, uses full regular expressions

-b Precede each line by the block number on which it was found. This
can be useful in locating block numbers by context (first block is 0).

Print only a count of the lines that contain the pattern.

Prevents the name of the file containing the matching line from being
appended to that line. Used when searching multiple files.

Ignore upper/lower case distinction during comparisons.

-l Print only the names of files with matching lines, separated by
NEWLINE characters. Does not repeat the names of files when the
pattern is found more than once.

-n Precede each line by its line number in the file (first line is 1).

-s Suppress error messages about nonexistent or unreadable files.

-v Print all lines except those that contain the pattern.

-w Search for the expression as a word as if surrounded by \< and \>.



find info on pppd in the process table:
ps -ef | grep pppd

find all companies in CA in the file database:

grep CA database

find the word disk in upper or lower case in all files:

grep -i disk *


Post a Comment

<< Home