SOC 103M Winter 2002 Final Solutions

Dana Dahlstrom

2002.03.20

  1. [54 points]
    1. [6 points] :%s/I/We/g
    2. [9 points] :%s/purple/orange/g or /purple followed by cworange or any other description of a working solution
    3. [3 points] 3G or :3 goes to line 3
    4. [3 points] 16| goes to column 16 in the current line
    5. [3 points] 2bw or bbw
    6. [3 points] $ goes to the end of the line
    7. [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).
    8. [3 points] 3k or kkk
    9. [3 points] 3G or :3 goes to line 3; "a2yy yanks lines 3 and 4 into register a
    10. [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
    11. [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
    12. [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.
    13. [3 points] :3,$d (or 3GdG if file has at least 3 lines)
    14. [3 points] :wq writes the current file and quits
  2. [72 points]
    1. [9 points] grep "see" burgess.txt | grep -v "seen"
    2. [6 points] grep -v "cow" burgess.txt
    3. [6 points] grep "^$" burgess.txt
    4. [6 points] sort -k3,3 burgess.txt
    5. [12 points] cut -c5,6 burgess.txt | sort > burgess_cols5and6.srt
    6. [3 points] wc burgess.txt
    7. [12 points]
      ls
      ls > listoffiles.txt
      ls | wc -l
    8. [12 points]
      cd ..
      cd - or cd so103class
      mkdir schlemiel
    9. [6 points] cp burgess.txt schlemiel
  3. [130 points]
    1. [4 points] { print $0 } or just { print }
    2. [16 points] { if ($0 ~ /u/) print } or just /u/
    3. [8 points] { print $NF }
    4. [10 points] { print $0, NF }
    5. [16 points]
       
      BEGIN {
        for ( x = 1; x <= 3; ++x ) {
          print x
        }
      }
      
    6. [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"
      }
      
    7. [40 points]
       
      { ++num_people_named[$1] }
      END {
        for (name in num_people_named) {
          print name, num_people_named[name]
        }
      }
      
    8. [4 points] pipe the output to sort