Grep for range of numbers

This should yield the desired result.

egrep "08:[2][5-9]:[0-5][0-9]|08:[3][0-5]:[0-5][0-9]" foo

Using cat in this case is not needed.


With these inputs:

01/15 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 08:25:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 08:35:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10

You can print all lines between two pattern, using awk:

awk -v date='01/14' '$1!=date{next};/08:25/,/08:35/' logfile

01/14 08:25:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 00:00:01  INFO:     received connect request from 10.10.10.10
01/14 08:35:01  INFO:     received connect request from 10.10.10.10

If you are open to use sed, you can do :

sed -n '/^01\/14 08:00/,/^01\/14 08:10/p' foo

In general, you can use bash variables replace with the specific times in the above command. For example:

st="01\/14 08:00"
en="01\/14 08:25"
sed -n "/^$st/,/^$en/p" foo #note the double quotes

You need to escape the / character with a \ if using / as separator as shown in the above command.