Search code examples
perlperl-module

Perl script Lookup timestamp in a log file


I have to make a modification to an existing PERL script. As I have no experience in PERL Scripting i googled and made a change but that's not working. So there is part that checks if a specific timestamp exists in the file. the code is

    while (<IN>) {
      if (/timestamp="(\w\w\w) (\d\d) \d\d:\d\d:\d\d (\d\d\d\d)"/ {
        $NowDate=$3.$Month{$1}.$2;
        if ( $NowDate > $StartDate ) {
          print OUT $_;
          while (1) {
            $regel=<IN>;
            if (! defined $regel) {last}
              print OUT $regel;
            }
          }
       }
  }
  • The timestamp in the log file = Feb 15 09:28:13 2017
  • but after upgrade the timestamp = 2017-02-15T10:26:14.858

i've updated the condition like this but it's not working.

if (/timestamp="(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)"/ 

Can anyone give me some advice here.


Solution

  • if ( /timestamp="(\d\d\d\d)-(\d\d)-(\d\d)T\d\d:\d\d:\d\d\.\d\d\d"/ ) {
        $NowDate = $1.$2.$3;
        ...
    }