SOC 103M Winter 2002 Final Solutions Dana Dahlstrom 2002.03.20 1. [54 points] a. [6 points] :%s/I/We/g b. [9 points] :%s/purple/orange/g or /purple followed by cworange or any other description of a working solution c. [3 points] 3G or :3 goes to line 3 d. [3 points] 16| goes to column 16 in the current line e. [3 points] 2bw or bbw f. [3 points] $ goes to the end of the line g. [3 points] 4G or :4 (or j from line 3) goes to line 4. ^ goes to the first non-blank character. 0 goes to the first character even if blank. Also, 4G and :4 already go to the first non-blank character (j doesn't). h. [3 points] 3k or kkk i. [3 points] 3G or :3 goes to line 3; "a2yy yanks lines 3 and 4 into register a j. [3 points] 4G or :4 (or j from line 3) goes to line 4; "ap puts the two lines from register a below the cursor k. [3 points] 1G or :1 goes to line 1; O begins a new line above the cursor and enters insert mode; ESC or Ctrl-[ exits insert mode after typing title and blank line l. [6 points] Ctrl-D scrolls down half a screen; Ctrl-U scrolls up half a screen; H moves the cursor to the first non-blank character of the line at the top of the screen; L moves the cursor to the first non-blank character of the line at the bottom of the screen. m. [3 points] :3,$d (or 3GdG if file has at least 3 lines) n. [3 points] :wq writes the current file and quits 2. [72 points] a. [9 points] grep "see" burgess.txt | grep -v "seen" b. [6 points] grep -v "cow" burgess.txt c. [6 points] grep "^$" burgess.txt d. [6 points] sort -k3,3 burgess.txt e. [12 points] cut -c5,6 burgess.txt | sort > burgess_cols5and6.srt f. [3 points] wc burgess.txt g. [12 points] ls ls > listoffiles.txt ls | wc -l h. [12 points] cd .. cd - or cd so103class mkdir schlemiel i. [6 points] cp burgess.txt schlemiel 3. [130 points] a. [4 points] { print $0 } or just { print } b. [16 points] { if ($0 ~ /u/) print } or just /u/ c. [8 points] { print $NF } d. [10 points] { print $0, NF } e. [16 points] BEGIN { for ( x = 1; x <= 3; ++x ) { print x } } f. [32 points] { tw[$2] += $3 } END { t_w_o = "Total weight of" print t_w_o, "females is", tw[2], "pounds" print t_w_o, "males is", tw[1], "pounds" print t_w_o, "everyone is", tw[1] + tw[2], "pounds" } g. [40 points] { ++num_people_named[$1] } END { for (name in num_people_named) { print name, num_people_named[name] } } h. [4 points] pipe the output to sort