Colorado State University

This file defines the header for each page. An optional "icon" image (I use the textbook):

Three headers follow: ! Long name of class !! Semester !!! HW 2, replaced by the name of the current page.

CS155: Introduction to Unix

Spring 2013

HW 2

Links to the various pages for this class:

Wish I could do this: * Schedule

CS155 HW2: Basic Unix and data manipulation

In this assignment, you will demonstrate some basic Unix commands by performing some simple tasks. To begin this assignment, look at the files located in the ~cs155/pub/hw2Files directory. The files contain information about people. For each person there are four files. For example, Sam would have the following four files:

sam.grades
The grades file—a list of the grades Sam got in her classes, one per line.
Each line of the file contains a number of fields, separated by semicolons (;).
The last field in each line is the name of a course.
sam.info
The info file—some basic information about Sam, including her age, favorite word, occupation, and how she approaches her job.
sam.jpg
The photo file—a picture.
sam.log
The log file—a list of dates in which information was logged about the person. The dates are formatted as MM.DD.YY.

Your primary objective in this assignment is to use your knowledge of Unix commands to collect and manipulate data contained in these files. For each of the problems listed below, you should give the command(s) you used. I want to see the commands, not the output of those commands.

Place your answers in a file named people, and submit it for HW2. It must not be called “hw2”. You may use pico to generate your submission, or any other editor that you prefer. Your submission should be formatted as follows, with blank lines between parts:

    1
    command
    command

    2
    command
    command

    3
    command

    4
    ... etc.

This time the grading is a little different: The difficulty of the questions vary. Some problems require multiple steps and some require complex commands. Each problem specifies a number of commands; you will be penalized for submitting an answer that uses more commands than were specified.

        cat foo
        date

Here are the problems:

Unless otherwise specified, assume that you start this assignment in your home directory. Assume that after each question you return to your home directory. A few of these problems will require some thought. Try to break the problems into individual commands and test out your ideas before assembling commands together. Good luck.

  1. (1 command : ½ pt) You should be in your home directory.
    Display the contents of the grades files for all people whose name begins with the two letters “ja”.
    (Don't just look at all the files, figure out which ones start with ja, and then write a command that only applies to those names. Your command should work no matter what people are in the directory.)
  2. (1 command : ½ pt) You should be in your home directory.
    List all the info and log files (What’s the command to list all files ending with .info OR .log?)
  3. (1 command : ½ pt) You should be in your home directory.
    Create a file named lousy in your home directory that contains the file names and lines (the data, not the line numbers) in those files where students scored less than ten out of a hundred.
  4. (2 commands : ½ pt) You should be in your home directory.
    Create a directory named brain in your home directory. Copy all info files into this directory.
  5. (2 commands : 1 pt) You should be in the ~cs155/pub/hw2Files/ directory.
    (Do not add this change of directory command to your list of commands)
    Create a file named courses in your home directory with a list of all the courses taken by anyone (e.g. courses listed in all grades files). Look at the manual page for cut, and be sure to use quotes on your delimiter.

    Second command: sort this file alphabetically and ensure each course is only listed once. Don’t change what’s in the file courses, just display the results.
  6. (1 command : 1½ pts) You should be in your home directory.
    Create a file named earlybirds in your home directory with a listing of all people who logged in on January 3rd 2006.
    • Use the .log files and search for anyone with an entry for the date specified.
    • Look in the manual for how to use the cut command in more detail to get just the name.
    • If the user logged in several times on that day, their name should only appear once in the file.
    • The file should be just a list of names–nothing but names.
    • Do this in steps until you get the whole thing.
  7. (1 command : 1 pt) You should be in the ~cs155/pub/hw2Files directory.
    Create a file log.info in your home directory containing two columns, where the first column is the number of times the person has been logged and the second column is the person’s name (use cut to remove the .log from the output).
    The file should be sorted in ascending order of the number of log entries (least on top). The last line of the file will be 42 total. (Hint: You will need to consult the cut and sort man pages for this problem.)
    The output looks like this:
     1 jane
     1 jill
     1 matilda
     1 mati
     1 sally
     1 sam
     1 wilma
     3 fred
     3 george
     4 alex
     7 gerry
     7 jack
    11 mary
    42 total

It doesn’t matter whether mati or matilda comes first.

Tips

% echo Go home: cd ~ >x
% echo "Go home: cd ~" >y
% cat x
Go home: cd /s/parsons/d/fac/applin
% cat y
Go home: cd ~

Useful information

How to submit your homework:

Did you call your file people? If you call it “hw2”, you’ll lose points.

Follow the directions on the homework page.

How to receive negative points:

Turn in someone else’s work.

Page: Main.HW2
Modified: November 08, 2012, at 10:48 AM
Wiki: pmwiki-2.2.35
CS Department
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2012 Colorado State University