Practice Test #3 Questions - answers at end Important Instructions 1. Read all the instructions and both sides of all pages. 2. Manage your time when answering questions on this test. Answer the questions you know, first. ________________________________________________________________________________ Multiple Choice - 44 Questions This is a practice test containing many practice questions. The real test will contain some questions similar to these. There are probably many more questions in this practice test than there will be time for in the real test. The real test will have approximately one question per minute. The real test may have some questions unlike anything given here. Knowing the concepts behind the questions is necessary; memorizing these specific answers won't help. The answers to this test are in the Answer Key on the last page(s). 1. Which command line deletes all the blank lines from the input file? a. awk -F' ' '{ delete; }' file b. awk '/^$/ == "" { delete; }' file c. sed -e ' d' file d. tr -d '[^$]' = 2 { print $(1+$2) } b. { print $(1+2) } c. RN >= 2 { print $(1+$2) } d. { print $1+$2 } e. $1 > 0 && $2 > 0 { print $(1+$2) } 9. A shell script named bar is executed as follows: ./bar a "b c" 'a ' Inside the script is the line: head $@ How many arguments are passed to the head command inside the script? a. 6 b. 5 c. 4 d. 3 e. 2 10. Which awk command outputs all lines where the second field is larger than the line number: a. $2 > LN { print } b. $2 > $LN { print $0 } c. NR < $2 { print } d. $NF < $2 { print } e. $2 > $NR { print } 11. What is the sed command to delete all empty lines (lines with no characters) from file file? a. sed -e '/^,$/ d' file b. sed -e '/^*$/ d' file c. sed -e '/^ $/ d' file d. sed -e '/^[^ ]$/ d' file e. sed -n -e '/./ p' file 12. Which sed command behaves identically to this: grep '.' file a. sed -e '/^[^ ]$/ d' file b. sed -e 's/.//g' file c. sed -e '/./ s/.*//' file d. sed -n -e '/./ p' file e. sed -n -e '/^$/ d' file 13. If guru=linus then which one of the following case patterns will match this statement: case "$guru" in a. [linus] | [LINUS] ) echo yes ;; b. "linu?" ) echo yes ;; c. * ) echo yes ;; d. lin? ) echo yes ;; e. (*nus echo yes ;; 14. Which sed command finds every occurrence of three adjacent letters and reverses them: (e.g. dogcatcow would become godtacwoc; but, do3ca;c.o would not change). a. s/\(![0-9]\)\{3\}/\3\2\1/g b. s/\([a-z]\)\([a-z]\)\([a-z]\)/\3\2\1/g c. s/\(![0-9]\)\(![0-9]\)\(![0-9]\)/\3\2\1/g d. s/\(^[0-9]\)\{3,3\}/\3\2\1/g e. s/\([^0-9]\)\([^0-9]\)\([^0-9]\)/\3\2\1/g 15. A shell script named bar is executed as follows: ./bar a "b c" 'a ' Inside the script is the line: head "$@" How many arguments are passed to the head command inside the script? a. 5 b. 4 c. 2 d. 3 e. 6 16. What is the output of the following sequence of bash commands: echo 'Good-day World' | tr -d -c 'W' a. GoodWay World b. GoodWay orld c. GoodW ay World d. W e. Good-day orld 17. What is the output of this bash shell program fragment? (There are blanks between all the letters in the word list section of the for loop.) in='' out='' for char in l i n u x ; do case "$char" in L|l) in=$in$char ; out=${out}L ;; [Xx]) in=$in$char ; out=${out}X ;; esac done echo "linux rox" | tr $in $out a. linux rox b. louux rox c. lINUx ROx d. LINUX ROX e. LinuX roX 18. Which sed command finds every line that ends in the digits 123 and removes the first occurrence of the string xyzzy from those lines: a. /[0-9][0-9][0-9]$/s/xyzzy// b. s/xyzzy.*123$/123/ c. /123$/s/xyzzy// d. s/^.*xyzzy\(.*123\)$/\1/ e. /xyzzy/s/[0-9][0-9][0-9]\$// 19. Which command line deletes all the blank lines from the input file? a. awk -F' ' '{ delete; }' file b. awk '/^$/ == "" { delete; }' file c. tr -d '[^$]' = 1 && (RN % FN == 0)/ { print } b. NR > 0 && (NF % NR) == 0 { print $0 } c. /FN >= 1/ { if (RN % FN == 0) print $0 } d. 1 <= NF && 0 == (NR % NF) { print } e. 1 <= RN && 0 == (FN % RN) { print } 29. If a script named bar contains a loop that starts: for i in "$*" ; do and the script is executed using this command line: ./bar a ' b d ' e f " g h " a how many times will the loop iterate? a. 6 iterations b. 9 iterations c. 8 iterations d. 7 iterations e. 1 iteration 30. A shell script named bar is executed as follows: ./bar a "b c" 'a ' Inside the script is the line: head "$*" How many arguments are passed to the head command inside the script? a. 1 b. 4 c. 5 d. 2 e. 3 31. Which awk command outputs all lines where the first field begins with the letters abc and the last field ends with the letters xyz: a. $1 ~ /abc$/ && $NR ~ /^xyz/ { print } b. $NF ~ /xyz$/ && $1 ~ /^abc/ { print } c. NR = /^xyz$/ && $1 = /^abc$/ { print } d. $1 == "abc" && $FN == "xyz" { print } e. $1 = /abc/ && $FN = /xyz/ { print } 32. If guru=linus then which one of the following case patterns will match this statement: case "$guru" in a. [linus] | [LINUS] ) echo yes ;; b. "linu?" ) echo yes ;; c. l?nus ) echo yes ;; d. lin? ) echo yes ;; e. guru ) echo yes ;; 33. If a script named bar contains a loop that starts: for i in $* ; do and the script is executed using this command line: ./bar a ' b d ' e f " g h " a how many times will the loop iterate? a. 8 iterations b. 7 iterations c. 12 iterations d. 9 iterations e. 6 iterations 34. Which sed command takes every occurrence of an asterisk (*) followed by a period (.) and reverses all of them: a. s/[*][.]/\2\1/g b. s/\(\*\)\(\.\)/\2\1/ c. s/(\*)(\.)/\2\1/g d. s/\(*\)\(.\)/\2\1/g e. s/\*\./.*/g 35. The sed command has the syntax format: sed 'Address1, Address2 Instruction Flag' Filename(s) If both Address1 and Address2 are omitted from the sed command, a. only the last line of the file will be examined for editing. b. only the first line of the file will be examined for editing. c. only the first 10 lines of the file will be examined for editing. d. all lines of the file will be examined for editing. e. only the last 10 lines of the file will be examined for editing. 36. Why is the instruction used in a sed command usually enclosed in a pair of single quotes (')? a. because single quotes are easier to type than double quotes. b. to forbid the shell from interpreting some of the special characters used in the sed instruction. c. to distinguish the sed instruction from the optional grep expression on the sed command. d. to prevent sed from interpreting the instruction as a file name. e. to permit the shell to expand the $USER variable in the sed expression. 37. Which sed command deletes only lines that contain at least one non-digit? a. s/^[!0-9]*$// b. /[0-9]/!d c. /[^0-9]/d d. /![0-9]/d e. s/![0-9]\+//g 38. What is the output on your screen of this command line: echo hi | sed -n -e 's/HI/HO/p' a. no output on screen b. HI c. ho d. hi e. HO 39. What is the output on your screen of this command line: echo hi | sed -e 's/HI/HO/' a. ho b. hi c. HO d. no output on screen e. HI 40. Which sed command finds every line that contains the four digits 1, 2, 3, and 4 in ascending order (but with any number of any characters in between) and deletes the first letter on these lines: a. /1.*2.*3.*4/s/[a-zA-Z]// b. /[1-1]*[1-2]*[1-3]*[1-4]/s/a-zA-Z/d c. /\1.*\2.*\3.*\4/[a-zA-Z]/d d. /[0-9].*[0-9].*[0-9].*[0-9]/s//[a-zA-Z]/ e. /(1)*(2)*(3)*(4)/[a-zA-Z]\1\2\3\4/d 41. Which awk command outputs the third field of lines that have at least three fields: a. 3 <= NF { print $(1+3-1) } b. FN >= 3 { print $3 } c. /$3/ { print $2+1 } d. /$3 != ""/ { print $1+1+1 } e. 2 < $FN { print $3 } 42. What is the output of the following sequence of bash commands: echo 'Good-day World' | tr -d 'W' a. Good-day orld b. GoodWay orld c. Good-day World d. GoodW ay World e. GoodWay World 43. Which sed command behaves identically to this: grep -v '.' file a. sed -e '/./ d' file b. sed -e '/./ s/.*//' file c. sed -e '/^$/ d' file d. sed -e 's/.//g' file e. sed -e '/-v ./ p' file 44. What is the output of the following sequence of bash commands: echo 'Good-day World' | sed -e 's/^/99/g' a. 99Good-day World b. 99ood-day World c. Good-day World d. 99Good-day 99World e. 99ood-day 99orld Answer Key - CST8129 - Ian Allen - Fall 2005 - CST8129 Practice Test 1. e 2. b 3. a 4. c 5. c 6. a 7. a 8. d 9. c 10. c 11. e 12. d 13. c 14. b 15. d 16. d 17. e 18. c 19. e 20. e 21. c 22. c 23. e 24. d 25. b 26. a 27. d 28. d 29. e 30. a 31. b 32. c 33. a 34. e 35. d 36. b 37. c 38. a 39. b 40. a 41. a 42. a 43. a 44. a Count of a: 12 27% Count of b: 6 14% Count of c: 10 23% Count of d: 8 18% Count of e: 8 18% With 5 choices: 44 Macro .cmd split with indent: 11