Difficulty: Easy
Correct Answer: ^pat
Explanation:
Introduction / Context:
Anchors in regular expressions control where a pattern can match within each line. Mastering these anchors is crucial for precise searches, log filtering, and data extraction with grep and related tools like sed and awk.
Given Data / Assumptions:
Concept / Approach:
The caret anchor ^ matches the beginning of a line. Therefore, ^pat matches lines that start with 'pat'. By contrast, the dollar anchor $ matches the end of a line, so pat$ would anchor at the end, not the beginning.
Step-by-Step Solution:
Verification / Alternative check:
Create a sample file with lines that begin with and do not begin with 'pat' and test the command. Only those starting with the sequence will be matched.
Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
^pat.
Discussion & Comments