Quiz1

21 January 2010

Note: Please remember that this quiz is designed to be completed in 30 minutes. You will see a similar question on your exams, so please make sure you are prepared to complete this question on time.

Your script must accomplish the following tasks:
1. Your script should read in a number of command line arguments
    a. The first argument is a file name, say fn.
    b. The second argument is a keyword, say k.
    c. Remaining arguments are a list of numbers separated by a space.
2. Once you get the numbers, you must find the maximum number in that list of numbers given.
3. Now that you have the maximum number, say n, you must find the nth occurrence of the keyword (k, given as the second argument) in the file (fn, the first argument) and print out that line number.

Example: If the command line argument is as follows:
>./quiz1.sh file1.txt unix 2 14 1 5 8 10 12 11 15 9 2
file1.txt contains:
1: unix
2: unix unix
3: unix unix unix
4: unix unix unix unix
5: unix unix unix unix unix
6: unix unix unix unix unix unix
7: unix unix unix unix unix unix unix
Your output should be "6" since the 15th occurrence of the word "unix" is in line 6.

Hand in your solution to "~yeng/15123-handin/your_andrew_id/R2"

Samreen Anjum
Last modified: Tue Jan 26 13:26:47 AST 2010