COP 3344-01 Introduction to Unix: Lecture 8
Learning objectives
After this class, you should be able to:
- Given a regular expression, identify the strings that it will match.
- Given specifications of the strings that a regular expression should and should not match, construct a suitable regular expression.
- Give
grep
oregrep
commands that will output all lines containing strings that match a specified criterion, from a set of files.- Explain the purpose of the following special symbols used in defining regular expressions: (i)
*
, (ii)()
, (iii)[]
, (iv)+
, (v).
, (vi)^
, (vii)$
, (viii)-
, (ix)|
, and (x)?
.
Reading assignment
- JEA: Appendix D,
grep
tutorial.- Lecture slides: Lecture 8.
Exercises and review questions
- Questions on current lecture's material
- Give a regular expression that will match all of the following strings:
"asty"
,"asbybyty"
,"asbyty"
, but none of the following strings:"asbbyyty"
,"asytby"
.- Give a regular expression that will match exactly the following type of strings: the string should start at the beginning of a line with the sequence of letters
ab
, it should end with the sequence of lettersnm
, and in between, it should contain one or more occurrences of either of the following patterns:123
or456
(some of the occurrences may be of one type, and others of the other type).- Use
grep
oregrep
to find all lines that start with a character other thana
or1
, followed by zero or more occurrences ofb
, followed by ac
, in all.txt
files in the parent directory of the current working directory.- Questions on next lecture's material
- None.