Assignment: Pipes and Filters
The purpose of this assignment is to demonstrate your ability to use Unix pipes and filters.
The Assignment
For security and administrative reasons, you must use the Unix account supplied to you by the University to prepare and email your assignment--failure to do so will result in your assignment not being graded.
You will be given a series of tasks to accomplish, each of which will require you to write a Unix command line involving pipes and filters. You will email to me each of the Unix command lines you create to accomplish these tasks. (See "Preparing Your Assignment" section, below.)
Phones Data
Your will work with data in a file called phones.dat which has the phone numbers of people in it. One person and phone number are on each line. On each line, the person's last name, followed by a colon, their first name, followed by a colon, and then their phone number with their area code in the parenthesis. You can assume that the last names and first names all start with a capital letter. But there might be any number of spaces before or after the : symbols.Each line is like this:
Here is an sample file of this format:Last name: First name: (area code)phone-number
Smith : Ellen: (414)555-8414 Van Buren: Henry: (262)555-1222 Jefferson: Ellen: (414)555-0887 Adams: John: (414)555-4149 Franklin:Ellen: (888)555-4140 Jimmy: Judy: (262)555-6262 Judy: Judy: (414)555-2622 Chicago: Judy: (312)555-1262 Denver: John: (906)555-1444 Boutros: Ellen: (414)555-2622 Henry: Henry: (262)555-4444 Conan: Ellen: (906)555-4144 Denver:Judy: (888)555-1333
You can get this sample data file via anonymous ftp from ftp.december.com in the directory pub, file phones.dat.
Important: you must write your assignment so that it works on any data file of this format, but which may contain different contents. You can assume the file is called phones.dat
Hints
- As you work to find the solution, you can build up your pipes and filters incrementally as you figure out the whole command line.
- Remember the -i and -w options on grep and how they work. Remember awk and how its separator field is set, and sort including the -b -f and -u options.
- You can consider using grouping, separator, or other symbols.
- Remember wc.
- Remember: Write your Unix pipes and filters to accomplish the tasks below in a general way so that it would work on any data file of the same format but different contents.
The tasks you must do
- TASK1:
Create a Unix command line that
shows the
count of the number of people in phones.dat with a phone number
in the 414 area code.
Based on the sample phones.dat file, your output should be:
5
Note that you can't just echo the number shown in the sample phones.dat file like this:
$ echo "5" 5 $
- TASK2: Create a Unix command line that
displays the information in phones.dat
but with every 262 area code changed to 373.
Based on the sample phones.dat file, your output should be:
Smith : Ellen: (414)555-8414 Van Buren: Henry: (373)555-1222 Jefferson: Ellen: (414)555-0887 Adams: John: (414)555-4149 Franklin:Ellen: (888)555-4140 Jimmy: Judy: (373)555-6262 Judy: Judy: (414)555-2622 Chicago: Judy: (312)555-1262 Denver: John: (906)555-1444 Boutros: Ellen: (414)555-2622 Henry: Henry: (373)555-4444 Conan: Ellen: (906)555-4144 Denver:Judy: (888)555-1333
- TASK3: Create a Unix command line that
displays a list of the unique
first names in the phones.dat file.
That is, show the list of first names only, but with
no repeats of first names and ignoring any leading blanks.
You can assume that the first names all start with a capital
letter, but they may have varying number of blanks in front
of them.
Based on the sample phones.dat file, your output should be:
Ellen Henry John Judy
Preparing Your Assignment
For your assignment, you can use Web-based mail (UW-Milwaukee students should use panthermail.uwm.edu) to write down and email to me a list of the command lines that you came up with to accomplish the tasks. Alternatively, you could create a file using the vi editor and then email the contents of that file.
In this list, show your answers to each of the Unix pipes and filters tasks. For each task n (n = 1, 2, 3), put the label "TASKn:" to the left of your answer on the same line for the task number n. Your answer to the right of the label should be the complete Unix command line that will yield the answer required. For example (note that these are not the correct answers to TASK1, TASK2, or TASK3), write your answers in your email message like this:
Please do this in exactly this format--including the exact spacing and symbols for the label "TASKn:" at the start of each line of your email message to me.TASK1: cat phones.dat | sed -e "s/414/ZZZ/g" | grep ZZZ | sort TASK2: cat phones.dat | grep -iw : | wc -l TASK3: cat phones.dat | awk -F: '{print "call: " $2}'
Remember, check for a receipt from me to make sure that I received your assignment before you consider the assignment done--remember "It's not complete until you get your receipt!"
Grading
Your assignment will be graded according to criteria I set up for this tutorial.For the 60% content score, each of the tasks is 20%. Partial credit will be given for answers close to producing the correct output. Some points off penalties include:
- -20% for no answer
- -10% if command produces no output
- -6% if command produces output but it would not work for any data file of the same format
- -6% (generally) off for each missing or incorrect argument that, if changed or added, would have given the correct answer
- -6% (generally) off for each missing or incorrect filter that, if changed or added, would have given the correct answer
- -3% (generally) off for each missing or incorrect option that, if changed or added, would have given the correct answer
- -3% (generally) off for each syntax error
Turning in Your Assignment
Your assignment is due by the time listed on the syllabus. Use these procedures for turning in your assignment. Your assignment will be graded according to criteria I set up for this tutorial.