performance
medium
Apply
regex
2 points
Question 29. CSCD240-E1-A
contacts.txt has Name<tab>number lines. Print only those whose number ends with 6.
Work the drill
Answer on paper or in a terminal before revealing the ideal answer.
Ideal answer
grep '6$' contacts.txt
Acceptable alternatives: ["grep \"6$\" contacts.txt", "grep -E '6$' contacts.txt", "awk '/6$/' contacts.txt"]
Misconception bank
Each row below is a plausible wrong answer, the thinking that produces it, and the remedy that corrects the misconception. These are the foundation of the multiple-choice framing and the targeted feedback a student receives after answering.
grep 6 contacts.txt
Misconception. Matches any line CONTAINING 6, not ending in 6.
Remedy. Anchor $ is required; demo on sample file.
grep '^6' contacts.txt
Misconception. ^ = start of line, wrong anchor.
Remedy. Symmetric pair: ^ vs $.
grep '*6' contacts.txt
Misconception. * in regex means "zero or more of previous char"; here it is a syntax error or weird match.
Remedy. Distinguish regex * from glob *.
Authority mappings
Hover any chip for the mapping justification; click to open the authority record.
DCWF roles:
CS-511 Cyber Defense Analyst
KU topics:
CD-BSP-T3
O*NET tasks:
SOC 15-1212.00: task 6
Course-artifact links
Lectures
- CSCD240-S26-L08. Pipes, filters, grep, sort, uniq, wc, tar
Lab questions
- CSCD240-S26-LAB5: Use grep with ^, $, [0-9], \. anchors.