Intro to Unix

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:

Last name: First name: (area code)phone-number
Here is an sample file of this format:
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

The tasks you must do

  1. 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
    $
    
    This echo would not work correctly for any data file of this same format. Another data file of the same format but with different contents might have 8,500 phone numbers in the 414 area code; another file might have 0. Figure out a command line that will come up with the right count for the number of phone numbers in the area code 414 no matter the contents of phones.dat. (You can assume that the file name is phones.dat and that you are searching for the 414 area code when you make your command line.)
  2. 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
    
    Note: don't actually change the contents of phones.dat. Just show to standard output what it would look like with the 262 area codes changed to 373.
  3. 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:

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}'
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.

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:

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.

search Search · star Market
2023-06-01 · John December · Terms © johndecember.com