======================= CST8129 Lab Exercise #8 (Week 11) ======================= -IAN! idallen@ncf.ca Due: demo in lab period only - no hand in Marks: 2% Late penalty: 100% after last lab on Friday this week. Purpose: - review some of the work done so far (Chapter 2) Demo procedure: When you are ready to demonstrate your work, put your name on the board at the front of the room under the column "first demo; section 01x". If there is time, I will see re-demos of the same work. Put your name on the board under "second demo". (Note: There may not be time for a second demo; make the first demo good.) Priority is given to people who are registered in a given lab section. If you are trying to give a demo in a section that is not your registered lab section, you must wait until after all the registered students have done their demos and have had their questions answered. Put your name on the board under "other sections demo". -------------------------------------------------------------------------- Instructions for your demo: You are to decode a file of text by making a correct series of global substitutions and replacements, in a given order, using VI and regular expressions (see Chapter 2 p.42/43). If you have still not completed the VI tutorial, you may not be able to finish this lab demo in time. (Editing shortcut: In command mode, after typing a ":" or a "/", the arrow keys work to allow you to edit the previous thing you typed.) Step 1: Run this "doright" program and save the output in a file named "right.txt" in your account somewhere: $ ~alleni/cst/lab08exercise/doright >right.txt $ wc -l right.txt 247 right.txt Make sure you have 247 lines in your file "right.txt". Step 2: Use the VI text editor to perform the following regular-expression substitution edits on the resulting "right.txt" file. Unless you are told otherwise, globally change *all* occurrences on each line, not just the first occurrence. (Use the "g" global substitution suffix shown in Section 2.1.1 of your text.) 1) From the beginning of every line, remove your userid and the single space that follows it. (Only remove it from the beginning of the line!) 2) From the end of every line, remove your userid and any number of spaces that might follow it. (The VI option "set list" is useful to have VI mark the ends of lines for you so that you can see spaces.) 3) Replace every occurrence of two periods with one period. (The escape shown in Table 2.1 will help you here.) 4) Replace every occurrence of two dollar signs with one dollar sign. (The escape shown in Table 2.1 will help you here.) 5) Change every occurrence of exactly three adjacent digits surrounded by one space on each side to the word "the" surrounded by one space on each side. 6) Find the letters "the" followed by one or more spaces and replace the multiple spaces with a single space. (Replace the one or more spaces following "the" with exactly one space.) 7) Remove a lower-case vowel (a,e,i,o,u) after every occurrence of the letters "ei". (e.g. "theiur" would become "their"). Only remove vowels! 8) Remove every occurrence of three characters (any characters) after the letters "op". (e.g. "opa1,en" would become "open"). 9) Find every occurrence of a string of letters (one or more upper or lower case letters), followed by a comma, followed by a space, followed by another string of letters, and exchange the places of the two strings. (e.g. "Canada, O" would become "O, Canada"). Both strings must contain only one or more letters. Step 3: Verify your work using the "diff" command. Compare your edited file with the following file and ensure that there are no differences: $ diff right.txt ~alleni/cst/lab08exercise/right-to-read.txt If your file is correctly edited, there will be no output from "diff". Any differences will be sent to your screen. Step 4: Demo: When you have finished making the above substitutions, call over your instructor. For full marks, you will be asked to demonstrate to your instructor how you performed any or all of the above substitutions and explain how the regular expressions work.