in reply to grep lines from log for last 10 mints
time is used to determine the current time as unix timestamp. Regular exression (some "word symbols", some space symbols, some numeric characters, some space symbols, then three groups of numeric characters delimeted by ":") is used to find the date from the string. Then it's parsed using str2time to unix timestamp, then it's compared to the timestamps found earlier, and the string being read is printed (print without arguments prints the special variable $_).perl -MDate::Parse -e'BEGIN{$main::now=time;$main::old=(time-60*10)}' +-nE'if(/^(\w+\s+\d+\s+\d+:\d+:\d+)/) {$t=str2time $1; $t > $old && $t + < $now && print}'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep lines from log for last 10 mints
by bimleshsharma (Beadle) on Aug 07, 2012 at 09:11 UTC | |
by aitap (Curate) on Aug 07, 2012 at 09:42 UTC |