UNIX® Shells by Example, Third Edition笔记2

1 egrep (Extended grep )

The main advantage of using egrep is that additional regular expression metacharacters (see Table 3.4 ) have been added to the set provided by grep. The \(\) and \{\}, however, are not allowed. (See GNU grep –E if using Linux.)

Table 3.4. egrep 's Regular Expression Metacharacters
Metacharacter Function Example What It Matches
^ Beginning-of-line anchor '^love' Matches all lines beginning with love.
$ End-of-line anchor 'love$' Matches all lines ending with love.
. Matches one character 'l..e' Matches lines containing an l, followed by two characters, followed by an e.
* Matches zero or more characters '*love' Matches lines with zero or more spaces of the preceding characters followed by the pattern love.
[ ] Matches one character in the set '[Ll]ove' Matches lines containing love or Love.
[^ ] Matches one character not in the set '[^A–KM–Z]ove' Matches lines not containing A through K or M through Z, followed by ove.
New with egrep:
+ Matches one or more of the preceding characters '[a–z]+ove' Matches one or more lowercase letters, followed by ove. Would find move, approve, love, behoove, etc.
? Matches zero or one of the preceding characters 'lo?ve' Matches for an l followed by either one or not any occurrences of the letter o. Would find love or lve.
a|b Matches either a or b 'love|hate' Matches for either expression, love or hate.
() Groups characters 'love(able|ly) (ov)+' Matches for lovable or lovely. Matches for one or more occurrences of ov.

你可能感兴趣的:(linux,unix)