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.
Give regular expressions that provide an answer to the following questions (one regular expression per item):
What is the first team from the list whose name starts with a capital letter H?
What is the first team from the list that participates in class C (name of class ends in C)?
What teams have a driver named Nico?
What teams have a serial number that exceeds 99?
What teams have a serial number that ends with the digit 2 and drive a car of the type OPEL?
What teams participate in class G and have a driver whose name (first or family name) contains a hyphen?
Try to keep the regular expressions a simple as possible, and make no assumptions about the lengths of the fields.
If you use a space in your regex, surround the entire regex in quotes (") in order for it to be evaluated correctly.