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
greporegrepcommands 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,
greptutorial.- 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:123or456(some of the occurrences may be of one type, and others of the other type).- Use
greporegrepto find all lines that start with a character other thanaor1, followed by zero or more occurrences ofb, followed by ac, in all.txtfiles in the parent directory of the current working directory.- Questions on next lecture's material
- None.