grep extract number range

You want the "alternation" regular expression token | to say "either this or that":

grep -E '2019-(09|10)-' file

See Why does my regular expression work in X but not in Y? for some background on regular expression tokens and regex classes (basic, extended, etc).


grep isn't good at handling numbers, it doesn't know how to compare them arithmetically. For that, you may want to use something like awk or Perl. That's not very important here, since it's easy to just list out 09 and 10, but if you had something like a range from 97 to 123 it would be much worse.

E.g. this would pick they year, month and day as numbers, and print out the lines where the day is between 27 and 31:

perl -ne 'print if /Last Password Change: ([0-9]+)-([0-9]+)-([0-9]+)/ && $3 >= 27 && $3 <= 31' < file

The regex is mostly like a grep ERE, the parenthesis capture the corresponding parts into the variables $1, $2, $3 etc.