======================== CST8129 Lab Exercise #11 (Week 14) ======================== -IAN! idallen@ncf.ca Due: demo in lab period only - no hand in Marks: 3% Late penalty: 100% after last lab on Friday this week. Purpose: - review some of the work done so far (Chapters 5-7) 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 perform a series of manipulations on a text file by writing a script that uses the "awk" program repeatedly. Each manipulation is independent of the others; these are not cumulative. Each awk program execution starts with a fresh copy of the input file. Step 1: Construct a shell script named "myawk.sh" containing a series of individual "awk" command lines to select the requested information from a file named "can-you-trust.txt" located under ~alleni/cst/lab11exercise/. Your shell script of awk command lines will look similar to this: awk >output1 '...your awk command...' INPUT || exit 1 awk >output2 '...your awk command...' INPUT || exit 1 ...etc... ...etc... ..etc... awk >output16 '...your awk command...' INPUT || exit 1 awk >output17 '...your awk command...' INPUT || exit 1 Replace all the words INPUT with the path to the "can-you-trust.txt" file. You may write a shell function to simplify the above script. Start with one awk command in the script file and gradually add the others until you have a working file that performs all of the editing correctly. Here are the selections you must perform on the input file (this list is also kept in file "index.txt" in the above lab11exercise directory): output1: Every line preceded by its line number. output2: Just fields 2, 5, and 7 from every line. output3: Lines that contain more than 14 fields. output4: Lines where the second field is exactly the string "the". output5: Lines that contain the string "the" anywhere in the second field. output6: Lines where the first field starts with a digit output7: Lines with at least 4 fields where field 1 is the same as field 4 output8: The first field of every line that contains the string "GNU" anywhere in the line output9: Lines with more than 3 fields where the third field is the same as the last field output10: Only the number of fields, in lines that contain more than 13 fields. output11: The first field and number of fields in lines containing the string "the". output12: Only lines that do *NOT* contain the string "the". output13: The line number and the line number plus (+) the field value for lines where the third field is numeric output14: The line number and number of fields of lines where the line number is equal to the number of fields output15: Fields 2, 5, and 7 for lines that have at least 7 fields output16: Fields 2, 5, and 7 for lines that have at least 7 fields and are after line 200 output17: The line number and number of fields of non-blank lines where the line number is an exact multiple of the number of fields Step 2: Verify your script output using the "diff" command. Compare all your edited output files with the following directory of correct output: $ mkdir empty $ cd empty $ ../myawk.sh $ diff . ~alleni/cst/lab11exercise/output/ If your files are correctly edited, there will be no output from "diff". Any differences will be sent to your screen. (You may also use diff to compare individual files, instead of the whole directory.) Step 3: Demo: When you have finished making the above selections, call over your instructor and demonstrate the execution of your script and the output of "diff". For full marks, you will be asked to demonstrate to your instructor how you performed any or all of the above selections and explain how the awk expressions work.