[LIST] Match A Single Character In A Specified List.

[LIST] Match A Single Character In A Specified List.

===> grep '[Dd]isk' fortunes

Disk crisis, please clean up!

On a clear disk you can seek forever.

I must have slipped a disk; my pack hurts.

===> grep '^stu0[2-6]a' /etc/passwd

stu02a:*:502:502:Student Account:/u/students/stu02a:/bin/ksh

stu03a:*:503:503:Student Account:/u/students/stu03a:/bin/ksh

stu04a:*:504:504:Student Account:/u/students/stu04a:/bin/ksh

stu05a:*:505:505:Student Account:/u/students/stu05a:/bin/ksh

stu06a:*:506:506:Student Account:/u/students/stu06a:/bin/ksh

Previous slide Next slide Back to the first slide View Graphic Version

Notes:

This slide is the first of many examples that illustrate combining the special characters for a compound regular expression.

The first example, illustrates when we want to first match an uppercase or lowercase character d; immediately followed by the lowercase characters i, s, and k. This expression states to find the word disk; spelled with a lowercase or uppercase character d. Since the are no spaces surrounding this word, harddisk and diskpack could satisfy this match from the fortunes file.

The second expression wants to match the s character starting at the beginning of the line; followed by the lowercase characters t, u, as the second and third characters to follow; and the fourth character is a 0 (zero). The fifth character must be a digit ranging from 2 thru 6. The final character to match is the lowercase character a.