Lab 8: Regular Expressions and Text Processing

Due Tuesday, October 15, by 9:00 AM


As usual, place the commands you used to solve each of the 5 problems into a file called lab8. This lab is essentially practice problems, intended to help improve command-line skills.
  1. 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.
  2. Use grep and wc to figure out how many words are exactly 10 letters long. Exclude words with an apostrophe (single quote).
  3. 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.
  4. The Nginx web server log in /var/log/nginx/access.log 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.
  5. isoptera hosts webpages for multiple classes at LCSC: cs253 (which you are taking), cs211, cs475, and cs101. Using the result of the previous problem, further sort out only lines which contain either cs253 or cs211. Then, use sed to replace course numbers with names: cs253 should be replaced with SystemsProgramming, and cs211 with C++. So an entry such as "/cs211/lab1.html" becomes "/C++/lab1.html", and "/cs253/syllabus.pdf" becomes "/SystemsProgramming/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.
  6. Write a brief program that will print out the current time using the ctime_r function . Don't use regular ctime (without _r).
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:
chmod 600 lab8