Review Exercise 4
Sobell, Chapter 12 (pg 476-477)
Awk Class Notes or AWK book Chapter 1-2
Due Date: 3/2/01


Please complete the following Review Exercises.
Place your answers underneath each question using a
Unix text editor.  Turn in your answers as follows: turnin ex4 exercise4.txt 

1. Assume you are working with the following history list:

   37 pine alex
   38 cd /home/jenny/correspondence/business/cheese_co
   39 pg letter.0321
   40 vi letter.0321
   41 cp letter.0321 letter.0325
   42 grep hansen letter.0325
   43 vi letter.0325
   44 lp letter*
   45 cd ../milk_co
   46 pwd
   47 vi wilson.0321 wilson.0329

   Using the history mechanism, give commands to do each of the following:

   a. Send mail to Alex
		!37 or !pine

   b. Use vi to edit a file named wilson.0329
		vi !$ 

   c. Send wilson.0329 to the printer
		lpr !$


2. How can you identify all the aliases currently in effect?

	just type: alias

3. How can you make tcsh always display the pathname of the working directory 
   as part of its prompt?

	set prompt = "$cwd % " 

4. Give the AWK commands to perform the following:

   a. Print the total number of input lines
		awk '{lines++};END{ print lines}' filename

   b. Print the total number of lines that contain Unix
		awk '/Unix/ {lines++};END{ print lines}' filename

   c. Print every line with more than four fields
		awk 'NF > 4' filename

   d. Print every line that has a least one field
		awk 'NF >= 1' filename

   e. Print every line with the first field replaced by the line number 
		awk '{ $1 = NR; print }' filename

5. Explain the difference between the BEGIN and END patterns.

	Commands within BEGIN{  } are executed only once, BEFORE any
   input has been read.

	Commands within END{  } are executed only once, AFTER all input
   has been read.

6. Explain the difference between the AWK built-in variables, NR, NF, $1, $0

	NR is the line number for the current line being read
	NF is the number of fields on the current line being read
	$1 is the first field of the current line being read
	$0 is the entire current line being read

7. If the variable A has a value of 10, what is the value after
   the following operations on A (assume A is equal to 10 at the beginning
   of each question):

   a.  A++
		11

   b.  A = A + 3.5
		13.5

   c.  A += 7 
		17

   d.  A = A * 3 
		30
	
   e.  A -= 10 
		0


8. How many times will the following AWK for loop iterate:

	for (i = 0; i <= 100; i += 2)
		print "hello"

	51 times

9. Which strings would the regular expression AB*C match:

    a. AB
    b. AC
    c. ABC
    d. ABBC
    e. ACC
    f. BC

	AB*C will match all strings with an A followed by zero or 
   more B's then followed by a C.
	Therefore, it will match choices: b, c, d and e.
	Try this to test it:  awk '/AB*C/' 
	then just enter the strings to see if they are echoed back.
	Type cntrl+d to signal end-of-input to quit AWK.