Practicum - week 7



1. Write a shell script that realizes the command 'letter'. Here is a fictive man page of this command:
 

NAME
letter - writes a letter
SYNOPSIS
letter <-l|b|a|n> <receiver> <sender>
DESCRIPTON
Creates a letter on the standard output. The first line says
'Dear <receiver>', the last line is the a signiture by the
<sender>, while the core of the letter is a text in the style
specified by the options. (Exactly one option can and must be
given.)

-l    creates a love letter
-b    creates a business letter
-a    creates an angry letter
-n    creates a letter in a nice style

AUTHOR
You, and nobody else.
REPORTING BUGS
By Mariette to you (the style of her report can be either l|b|n|a).
COPYRIGHT
(C) 2002 Tekstmanipulatie, RUG


SEE ALSO

Lecture notes on Shell scripts (week 5 and 7).


(3 points)
 

There is an easy way to include more than one options, in the way 'letter -lb', 'letter -nal', etc. (I'm not speaking of including more options as 'letter -a -l -n'). Can you do that? What will be the output? What is the result if you include more than one option in a different order (e.g. '-la' as opposed to '-al')?

There are several solutions for writing the command leading to several results.

(1 point)
 
 
 

2.

Write a shell script that is similar to the one last week (exercise 3), but that does not returns the word lists, rather the Zipf functions (in the number of tokens, i.e. absolute frequency). That is the result should look like a four-column table (that can enter Excel, e.g.): the first column shows the rank from 1 to 50, and the 2-4 columns give the frequencies of the given file. The file names should be again the arguments of the script's name.

(3 points)

Here are some results I produced:

birot@hagen:~> zipf Federalist/fed1.txt Federalist/fed11.txt Federalist/fed12.txt

rank Federalist/fed1.txt Federalist/fed11.txt Federalist/fed12.txt
1 3569 4967 4340
2  117  181  161
3   98  178  142
4   62   81   82
5   37   70   57
6   34   66   46
7   26   63   45
8   25   46   40
9   24   44   26
10   23   34   23
11   17   25   22
12   15   23   22
13   14   21   21
14   14   20   19
15   14   20   18
16   14   19   17
17   13   18   16
18   12   18   15
19   12   18   14
20   11   17   14
21   11   16   14
22   11   15   14
23   10   15   14
24   10   13   13
25   10   13   13
26    9   13   13
27    9   12   12
28    9   12   11
29    9   12   10
30    8   12   10
31    8   11    9
32    8   10    8
33    8   10    8
34    8   10    8
35    8    9    8
36    8    9    8
37    8    9    8
38    7    9    7
39    7    9    7
40    7    9    7
41    6    8    7
42    6    8    7
43    6    8    7
44    6    8    7
45    6    7    6
46    6    7    6
47    6    7    6
48    6    7    6
49    6    7    6
50    6    7    6
 
 
 
 

3.

The Fibonacci-numbers are a series of numbers whose rule is that the next element of the series is the sum of the two previous ones:

a(n+1) = a(n-1) + a(n)
For instance if the first two elements are 1 and 1, then the Fibonacci series is: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, etc. This series has a lot of nice properties. For example, the ratio of two consequtive elements is converging towards the ratio of the so-called "golden mean" (the ratio of the smaller to the bigger is equal to the ratio of the bigger to their sum).

Write a shell script that enters the first two elements as its arguments, and outputs the Fibonacci-series generated by them. In order not to run into an infinite loop, stop when you reach 10,000.

(3 points)