regexgrepregex-alternation

How to use grep with alternating part of the regular expression?


I want to grep all dates in August or September (date format mm/dd/yyyy with leading zeroes).

I tried:

grep '0\(8\|9\)/[0-9][0-9]/2012'

But command prompt outputs:

The system cannot find the path specified.


Solution

  • grep wants a regular expression and a file name. The error message looks like you somehow passed an invalid file name. Assuming the file containing the log entries is named log, try this;

    grep '0[89]/[0-9][0-9]/2012' log
    

    (I also tweaked your regex a bit.)