answers are in www.csua/~jlau/cs9e/answers2.txt when you take the final, you will be given printed copies of the following manpages: awk, find, grep, ls, sed. things you should know: basic usage of the following commands: cd, ls, cp, mv, rm, ln, mkdir, cat, tr, cut, head, tail, comm, diff, sort, wc, finger, alias, scp, ssh, find don't worry about arguments to these commands that you haven't learned about... if you've been quizzed on some aspect of the program or you've used some argument in one of the homeworks, you should know it... for example, you should know how to sort with multiple sort keys, how to hide columns of comm's output, how to have find run commands on the files it finds, etc... you need to know how to read a manpage... specifically, what something like this means: ssh [-afgknqtvxCPX46] [-c blowfish | 3des] [-e escape_char] [-i identity_file] [-l login_name] [-o option] [-p port] [-L port:host:hostport] [-R port:host:hostport] [hostname | user@hostname] [command] you need to know how to write simple shell scripts. you won't be writing anything big for the final [remember we have to grade these things...] but you should know simple flow-of-control structures like if statements, foreach, switch, goto, etc. you need to know what the different types of quotes ['"`] mean to the shell. you should know the following ftp commands: ascii, binary, cd, get, lcd, mget, mput, prompt, put you should know how to write a simple makefile [like the ones on the quizzes and homeworks] regular expressions. know what the following symbols mean: * . ^ $ [ ] \( \) you should know the following sed commands: d, n, s, p, a, i, c you should know the following awk commands: print, if, while, for practice problems in no particular order: 1. describe how you would modify your .login to print out the sender of *new* emails you have received since your last login... so, the first time i login, it should print out the senders of all the emails in my mailfile... if i login again, and nobody has sent me email since my last login, nothing should be printed... if i received only one email, only the sender of that one email should be printed out. 2. so you've been downloading lots of song lyrics... you're getting frustrated, though, because people have gone and formatted them in their own strange ways [some people center all their lyrics, some people use all uppercase, some people have leading blank lines, trailing blank lines, etc...] and you want your collection of lyrics to look consistent. write up a shell script that takes in the contents of a lyrics file on standard input, and produces a cleaned up lyrics file on standard output by accomplishing the following tasks [your shell script can call sed scripts or whatever else you want...]: 1. make everything lowercase 2. turn consecutive spaces into one space, and remove leading and trailing spaces... so something like [in the following example, spaces are represented with '_'] ____come_down_and_waste_away_with___me____ ... should turn into ... come_down_and_waste_away_with_me 3. turn consecutive blank lines into one blank line, and remove leading and trailing blank lines... [this means the first line and last line of your output should not be a blank line] for this exercise, consider a line that contains only spaces as blank, too. 3a.assume you have a command 'mpg123' that takes in one argument, the name of a mp3 file, and plays it. when it's done playing, the program exits. this mp3 player is non-interactive. assume also that your mp3's are named ..mp3, for example, portishead.sourtimes.mp3. we also have been collecting lyrics for songs... so there might be a file called portishead.sourtimes.txt in the same directory that contains the lyrics for the song. modify your shell script so it displays the artist and title of the currently playing song, and lyrics, if available, instead of just displaying mpg123's output. [this means you should hide mpg123's output. note that mpg123 produces its output on the standard error, not standard output] it's sufficient to just take off the '.mp3' extension, so output will look like this: currently playing <artist>.<title> <lyrics, if available> [tricky... don't worry if you can't get this one] 3b.right now your shell script most likely plays your mp3s in the order they appear in the directory... modify your shell script so that it plays mp3s in random order. 4a.a friend of yours adds new directories onto the end of their PATH all the time. since you've taken 9e, you feel like making their life a little easier, so you decide to make a shell script called addpath that will take one command line argument, and add it onto the end of the path. so, you write up a shell script [in csh... you can rewrite it in bourne shell if you want, the problem isn't specific to csh] that looks like this: #!/bin/csh setenv PATH ${PATH}:$1 echo your path is now $PATH why do we need curly braces around PATH on the second line? [what would happen if they weren't there?] 4b.within a couple minutes your friend tells you that he's getting "command not found" errors. what should your friend do to fix this? 4c.the error message has gone away, but your friend claims that your script doesn't work. he emails you output that looks like this: jlau@soda:~ 63% echo $PATH /bin jlau@soda:~ 64% addpath /usr/bin your path is now /bin:/usr/bin jlau@soda:~ 65% echo $PATH /bin why is this happening? 4d.how can you work around this problem? [without resorting to using setenv PATH ${PATH}:___ whenever you want to add something to your path] 5. i need to seperate out the even and odd numbered lines of a file. show me how to do this using your 9e knowledge [you can use whatever tools you like]. i actually had to do this for cs152... so, if i have a file called data that looks like this: a b c d i want to be able to split it into two files, one that contains a c and the other contains b d 6. a program that you've written [suppose it's called a.out] produces two kinds of messages on standard output: warnings and errors. each message is exactly one line long. errors have three asterisks [***] at the beginning of each line, warnings do not have three asterisks at the beginning. i want to run your program, but i only want to see the error messages. how can i do this? 7. suppose i'm currently logged into torus.cs as user jeremyl. since i'm taking cs186, i also own the account cs186-ay. i've been told that the midterm solutions are online at www-inst.eecs/~cs186/midterm_solution.pdf, but the web server is broken. write a scp command that fetches the midterm solution. for this question, assume that www-inst.eecs allows ssh/scp connections, and assume that the midterm solutions are accessable only to cs186 logins [so i can't just login as jeremyl to copy the solutions, i must login as cs186-ay].