2
0

extract_log_range.pl 693 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl
  2. use Time::Local;
  3. my $file = shift;
  4. my $start = shift;
  5. my $stop = shift;
  6. sub parse_date($) {
  7. my $str = shift;
  8. if (my ($yr, $mo, $day, $hr, $min, $sec) = $str =~ /(\d{4})\-(\d{2})\-(\d{2}) (\d{2})\:(\d{2})\:(\d{2})/) {
  9. return timelocal($sec, $min, $hr, $day - 1, $mo - 1, $yr);
  10. } else {
  11. die $str;
  12. }
  13. }
  14. if ($start =~ /\:/) {
  15. $start = parse_date($start);
  16. }
  17. if ($stop =~ /\:/) {
  18. $stop = parse_date($stop);
  19. } elsif ($stop =~ /^\+(\d+)/) {
  20. $stop = $start + $1;
  21. }
  22. open(I, $file);
  23. while (<I>) {
  24. my $str = $_;
  25. $epoch = parse_date($str);
  26. if ($epoch > $start) {
  27. if ($stop && $epoch > $stop) {
  28. last;
  29. }
  30. print;
  31. }
  32. }
  33. close(I);