Page 184 of the reference book explains how regular expressions can be used to perform searches in the text editor vi. In this exercise you will practice how to formulate such regular expressions. For this purpose we will make use of the line based text editor ed. We will continue to make use of the text file participants.txt1. This file contains the starting list for a car race competition. If necessary, inspect the file using nano, vi or emacs. Lines in participants.txt2 take the form:

<team name>:<serial number>:<nationality>:<car type>:<class>
  

Open the file by executing the command ed participants.txt If you now enter a regular expression (followed by pressing the <ENTER> key), the text editor ed will write out the corresponding lines from the file. As such, the regular expression /OPEL will return the first line that contains the text OPEL. In order to return all lines that contain the text OPEL, you should add the letter g in front of the regular expression: g/OPEL. Use the command q to exit the text editor ed.

Assignment

Give regular expressions that provide an answer to the following questions (one regular expression per item):

Try to keep the regular expressions a simple as possible, and make no assumptions about the lengths of the fields.

Attention

If you use a space in your regex, surround the entire regex in quotes (") in order for it to be evaluated correctly.