GREP stands for
Global Regular Expression Printer.
$ grep options
pattern filename(s)
Options:
-i ignore case -c count
lines
-v inverse role -l file
names only
-n lines are numbered -f patterns
in a file
-e multiple patterns -E EREs
REGULAR EXPRESSIONS
USING GREP
Basic Regular
Expressions (BRE):
* Zero or more occurrences
of the prev. chr.
. A single Character
.* Any no. of characters or
none
[abc] a or b or c
[a-z] any character between a to z
[1-3] any digit between 1 to 3
[^abc] not a or not b or not c
REGULAR
EXPRESSIONS USING GREP
Basic Regular
Expressions (BRE):
[^a-zA-Z] non-alphabetic character
abc exact character sequence abc
^abc abc not at the beginning of the
line
abc$ abc not at the end of the line
^abc$ abc as the only word in line
^$ lines containing nothing
\ nullify the meaning of
meta characters
REGULAR
EXPRESSIONS USING GREP
Extended Regular
Expressions (ERE):
ab+c a followed by one or more b’s followed by c
ab?c a followed by optional b followed by c abc or ac
a|b either a or b
(a|b)c either ac or bc
REGULAR
EXPRESSIONS USING GREP
Interval Regular
Expressions (IRE):
ab {2,4}c a followed by 2,3,4 b’s followed by c
ab{2,}c a followed by at least 2b’s followed by c
ab{2}c a with 2b’s and c
Ex:
grep –i ‘abc’ emp.lst emp.lst1
No comments:
Post a Comment