Lab 8: Regular Expressions and Text Processing
Due Thursday, March 19, by 9:00 AM
As usual, place the commands you used to solve each of the 5 problems into a file called lab8
Turn in your lab by creating a file named "lab8" with no extension in your home directory, with permissions set so that only you can view the file. This assignment is worth 35 points, 5 from correct naming and permissions, and 5 from each of the problems above. As a reminder, you can set the permissions correctly with this line:
- Recall the word finding demo from in-class. Use the dictionary located at /usr/share/dict/ called american-english to find a list of words which contain an r (upper or lower case), followed by two letters (any letter), followed by a k (upper or lower case). Also, allow one additional letter on either end of the pattern. So some words that match are wrack, trick, rank, ranks, crocks, etc. Words with more letters on either end, like rocket or windbreak should not match.
- Use grep and wc to figure out how many words are exactly 10 letters long. Exclude words with an apostrophe (single quote).
- Two common three-letter sequences to find at the beginning of English words are non (such as nonsense, none, or nonstop) and pre (such as predict or preface or predestination). Use grep and wc to figure out which sequence is more common. This will be easiest with two commands, one for non and one for pre.
- The Apache web server log in /var/log/apache2 contains a great deal of text, which can be difficult to read. Notice that requests for web pages contain GET. Use grep and cut to display ONLY web pages requested, not any of the other information in the file. Sort out other types of queries such as POST. I suggest starting with grep to select only lines containing GET, and then using cut with a space as the delimiter, but the method is up to you.
- isoptera hosts webpages for multiple classes at LCSC: cs253 (which you are taking), and cs435. Using the result of the previous problem, further sort out only lines which contain a course name. Then, use sed to replace course numbers with names: cs253 should be replaced with SystemProgramming, and cs435 with Networks. So an entry such as "/cs435/lab1.html" becomes "/Networks/lab1.html", and "/cs253/syllabus.pdf" becomes "/SystemProgramming/syllabus.pdf". If you feel the pipe has become too long to manage, you can save an intermediate result (such as the result of question 4) in a file and work from there. Remember, > can be used to redirect output into a file.
- Write a brief C program that will allocate an array of 10 integers on the heap. Use malloc for this. Store at least one number in the array, print the number out, and then free the array.
chmod 600 lab8