CSC 4630 - 001

Software Development and Systems

Lab #2

Due Date: March 12, 2013 (Tuesday)


Coverage (of exam, too):


Note: Since some of your scripts will actually be run against particular data, it's even more critical than before that the uploads (a) are done as described in these pages, (b) be named exactly as specified (ie, correct upper/lower case characters; no "txt" or other file extension unless explicitly required), and (c) be uploaded this time as individual (not zipped or compressed in any way) files.

It's critical that no program crashes. You'll get more credit for a program that does nothing or gives incorrect results than for one that has a syntax or logical error that causes the grading script to crash! Remember, too, that the work is individual, the shell scripts are Bourne. Again, The different questions have different weights.


    UNIX

    metagreps) Create a file called greps, consisting of the ten lines of excercise 3.3 in K&P, p. 79, one command per line. Now in metagreps, give and explain the output of the following Bourne shell commands (most of which look at greps):

    grep -n gr greps
    grep -n 'gr' greps
    grep -n \\g\r greps
    grep -n \\\\\\\\\\\\ greps
    grep -n '$' greps
    grep -n '"$' greps
    grep -n '\$' greps
    echo "This is a `cat /mnt/a/goelman/opinion`"
    set a b c d
    echo "It isn't worth $2.00."
    
    Notes:

  1. There are 12 backslashes in the fourth line above.
  2. Two lines later, the punctuation goes single quote, double quote, dollar sign, single quote.
  3. The last two lines above should be done in the same sitting.
  4. shellvars) Give the output you get to the Bourne shell command set, and explain three of the variables.

    backup) Write this Bourne shell script. Its output is the list of its arguments, in reverse order. If you have tried it and would like a hint, send Akhil an email with what you've attempted, and he'll give you one. It should work like this:

    $ backup This is a test.
    test. a is This
    $
    
    If you can get it to work on five or fewer arguments (but not the general case), you'll get partial credit on this one.

    sendstuff) This file should be a shell procedure that takes at least two arguments. The first argument is the addressee (there's only one). The other arguments are all files to be mailed to that addressee, preceded by their name. Here are some hints: if a variable i is cycling through the different file names, then echo $i will produce its name (onto stdout, of course), while cat $i will produce its contents (ditto). The other hint is to look up the shift construction. Since you lose $1 when you shift, be sure to save $1 somewhere first! You can implement this either way: have each individual file go in its own message, or have all the files go in a single message.

    oneword) This prints all the lines of its file argument that have only one word in them. By word is meant any sequence of non white space characters on a line (let's consider "white space" to be consecutive space or tab characters). Of course a line may have leading or trailing white space on it.

    nodigits) This script also takes a file as its argument and also uses grep. Its output is all lines of the argument that contain no digits.

    moredips) This is another Bourne shell program that uses grep. It also takes a file name as its argument. Its output this time is all lines in which the some diphthong appears in a line, and then reappears in the same line. A diphthong here is two vowels in a row. Don't count y as a vowel in this case.

    sedsizes) This program produces a list of the files in the current directory, each preceded by its size. It uses sed, not awk, to filter the output of ls -l.

    awksizes) This does the same thing as the last program, but it does use awk (so it's easier).

    The next three files are awk scripts. In other words, they're not stand-alone Bourne shell programs. Instead, they're invoked, e.g., by the format

    $ awk -f Asiapop.awk /mnt/usr/DATA/world
    
    Thus, they operate on a specific database. Its layout is explained in /mnt/usr/DATA/world.fields.

    Asiapop.awk) This script gives the population of the continent Asia.

    avgpop.awk) This one gives a list of the continents, each with the average population of its countries. The names of the continents aren't known in advance, so they can't be "hard-coded" into this script.

    chem.awk) This gives the list of countries in which chemicals are part of their economy. (note: it might not be the only kind of product in those countries).


    Back to CSC 4630 Homepage