QuestionQ163

Essential Commands

Given a file named birthdays containing lines such as:

YYYY-MM-DD Name -  
1983-06-02 Tim  
1995-12-17 Sue  

Which command would output the lines for every listed person whose birthday falls in May or June?

  • A grep '[56]' birthdays
  • B grep 05?6? birthdays
  • C grep '[0-9]*-0[56]-' birthdays
  • D grep 06 birthdays | grep 05
Explanation

In an ISO-style YYYY-MM-DD date, the month field is bounded by hyphens. The regular expression [0-9]*-0[56]- matches a numeric year followed by either month 05 or 06, ensuring that it selects May and June dates rather than arbitrary occurrences of those digits.

Community Discussion

No comments yet. Be the first to start the discussion!