CSCI 241 - Homework 3
Due by 11:59.59pm Sunday, 28 February 2016
Give a command that will use a single egrep or grep -E on
/usr/share/dict/words.241 to find the following.
Consider only a, e, i, o, and u as vowels for our purposes.
Put your answers in a file called README.
You may want to review the lecture notes, the class readings, and possibly do an online tutorial before beginning. There are useful links for regex visualizers on the course home page.
Protip: you can do
export WORDS=/usr/share/dict/words.241 and then use
$WORDS as your input file. Also, piping output to
wc -l will let you count the lines output.
- All words that contain exactly one lowercase vowel (5948 on clyde)
- All words that contain the lowercase vowels a, e, i, o, and u in that order (6 on clyde)
- All words that are exactly 22 lowercase letters long (2 on clyde)
- All words that have a 4-letter sequence repeated (24 on clyde)
- All words that start and end with the same 3 letter sequence (32 on clyde)
- All lowercase words that are made up of only pairs of consonant-vowels like banana and are at least 6 letters long (545 on clyde)
- All words that end with their first 3 letters reversed like detected (14 on clyde)
For this portion of the assignment I want you to construct sed commands that will
do the following activities. (Don't forget the
- Replace all instances of "snow fall" or "wind chill" with "summertime"
- Assuming the input is a dictionary file like /usr/share/dict/words.241 (one per line, alpha order), print out all words between "computer" and "science"
- Replaces all instances of "Teh" with "The" and "teh" with "the", but only in standalone words
- Move the last word on a line to the front
- Find lines where a word has been repeated on the same line and replace that line with a repeated word. Don't print the other lines.
- Delete all shell comment lines, that is lines with optional whitespace followed by a #. Don't delete them if the comments are on lines that have actual instructions (i.e., something other than whitespace before the #)
- Convert C block comments that are on one line and at the end into a line comment.
So /* add things up */ would become // add things up
- Only print out lines that contain "cs 241", but change that to "CSCI 241"
- Take the previous, but modify it to handle "CS" or "CSCI" with or without space and of any type of capitalization (e.g., "cScI241")
- Truncate all lines after exactly 20 characters.
- Replace all instances of "Thomas B. Wexler" with "T-Wex" (including variations with "Tom" and/or no middle initial)
- Assuming that a name is made up of two adjacent words that start with a capital and are followed by one or more lower case letters, anonymize the input by changing every name to be just their initials. So "Roberto Hoyle" becomes "RH". Be sure to handle having multiple names on the line.
- Check to see if there is a 10 digit number on a line which may have non-letters between the digits and print it out in the format 1234567890
- If there is a 10 digit number on a line (not part of another word) reformat the number as (123) 456-7890
- Assume that the input is being piped from wget --quiet -O- http://xkcd.com/ (which will print the xkcd comic's html page to stdout), print out the Image and Title information as follows:
Title: I'm the Philosopher until someone hands me a burrito.
You may find the following links useful when working on this assignment:
Handin your README
Be sure your README document has your name and the honor code statement and
hand it in (or the folder containing it).
% handin -c 241 -a 3 README
% lshand 241
Once you are done, try out Regex Golf!
Last Modified: Sep. 24, 2015 - Roberto Hoyle