CS/CE 218 Lab 5 26 September 1991 There's no report due for this lab! The exercises contained in this lab are intended to help you with the homework that's due tommorrow, as well as exploring shell scripts, redirection in pipelines, tee, join, and sed. 0. Put the directory $PUB/lab-data/lab5 in your shell's PATH set PATH=:$PUB/lab-data/lab5$PATH export PATH 1. The file $PUB/lab-data/lab5/pipe-test contains the following: #!/bin/sh echo "some text" | pg < $PUB/homework/hw2.txt (you might want to verify this...) Run the command pipe-test a. What happened to the output of the echo command (the words "some text")? 2. The file $PUB/lab-data/lab5/cut-tee-test contains the following: #!/bin/sh ps -fl | tee ps-out | cut -c79-,4-36 | tee cut-out Run the command cut-tee-test a. Examine the contents of ps-out and cut-out. Why is the content of ps-out different from the content of cut-out? (this should be obvious) b. Why do the contents of cut-out match what you saw on standard output? (this also should be obvious) 3. The file $PUB/lab-data/lab5/join-test contains the following: #!/bin/sh HW2=$PUB/hw2 if test $# -ne 3 then echo "need 3 arguments" >&2 exit 1 fi join $HW2/$1 $HW2/$2 | tee join12 | join - $HW2/$3 a. What is the output of the following? join-test people live occupation b. What did first part of the pipeline produce? 4. This problem concerns using sed for substitutions. The command sed -e 's/xxx/yyy/' substitutes yyy for the first occurrence of xxx on each line in the command's standard input. The command sed -e 's/xxx/yyy/g' changes EVERY occurrence of xxx to yyy on each line its standard input. (Think of ``g'' as ``global'') a. What is the exact format of the file $PUB/hw2/people? Are the fields separated by blanks or tabs? (Try editing the file and moving around in between the fields) What columns do the fields start in? (In emacs, try C-x =) b. The file $PUB/lab-data/lab5/simple-sed-test contains the following: #!/bin/sh # below / */ has two blanks, and then / / has a tab. sed -e 's/ */ /g' < $PUB/hw2/people Run the command simple-sed-test What is the output? c. How could you do what was done in part (b) without using sed? 5. The file $PUB/lab-data/lab5/saving-sed contains the following: #!/bin/sh sed -e 's/^\([^ ]*\) *\(.*\)$/x\2y\1z/' < $PUB/hw2/occupation a. Run the command saving-sed Explain the output in terms of the above command. That's it, you're all done. But if you want to experiment more, you can try some or all of the problems in /home/cs218/public/homework/lab5-extra-credit.txt (However, you should perhaps do homework 2 first.)