But all of these would work only if the exact time stamps are known and given. Should that not be the case, you'll need to read every line and interpret/calculate the time values before comparing to the lower and upper limits.
@MadeInGermany - your suggestion is working if the time value is lower to higher but if the time value is higher to lower then the output is completely different .
RudiC , The idea, script to collect the logs for every 45 mins and check the errors automatically.
I found the below perl script in other post, it is working perfectly for my requirements, since "from" and "to" time is unknown, can you help me to create the Perl script to take the current time for "from" and "-30" mins for "to".
I went back and read your first post and this will not do what you said your requirements are. Nevertheless, just so you believe me I will convert it to what you asked.
Even, if modified to accept a current time for to and 30 minutes ago for from , the condition if will not match any entries in your posted log. Substituting it for if /^(\d{6}\s+\d{2}:\d{2}:\d{2})/ it will match your time stamp format, but it will not print properly those entries in between that do not contain a time stamp.
Please, try the following:
Save as entries.pl and run as perl entries.pl log.txt
#!/usr/bin/perl
# this is not tested since I do not have any valid log files.
use strict;
use warnings;
use POSIX qw(strftime);
my $now = time;
my $ago = $now - (30*60);
my $from = strftime('%y%m%d %T', localtime($ago));
my $to = strftime('%y%m%d %T', localtime($now));
while(<>) {
print if /$from/../$to/;
}