CS155: Introduction to Unix

Spring 2018

HW 2

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, and any other random information that Sam wishes to include.
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 for month-day-year.

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 simple, and submit it for HW2. It must not be called “hw2”. You may use nano 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 “ge”.
    (Don't just look at all the files, figure out which ones start with ge, and then write a command that only applies to those names. Your command should work no matter what people are in the directory. Think “patterns”.)
  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 substandard in your home directory that contains the file names and lines (the data, not the line numbers) in the grades 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 data 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 classes in your home directory with a list of all the classes taken by anyone (e.g. classes 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 classes, just display the results.
  6. (1 command : 1½ pts) You should be in your home directory.
    Create a file named fire in your home directory with a listing of all people who logged in on July 4th 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. No dates, no slashes, no colons.
    • 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 (fewest on top). The last line of the file will be the 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 george
     4 alex
     5 fred
     7 gerry
     7 jack
    11 mary
    44 total

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

Tips                

% echo Go home: cd ~ >bad
% echo "Go home: cd ~" >good
% cat bad
Go home: cd /s/bach/a/class/cs155
% cat good
Go home: cd ~

Useful information                

How to submit your homework:                

    ~cs155/bin/checkin HW2 simple

Follow the directions on the homework page.                 

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-01-28T16:27                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building