1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    Help Newbie to Perl

    Hi, I am looking at parsing a file and picking out user numbers, date and time. An example of the line in the file is as follows.

    2011-04-18 06:27:55,063 [Default_Transport_To_Channel_pool : 4] [timapp1-HandlerMethod-qAkvRwsOhgs9chuKeNwfrr4-0767567--timcentrea-] INFO Tim_LOG - ControllerMethodInterceptor uk.co.td.remote.view.controller.AuthenticationController.logonVersion1 success 9ms

    I need to display 2011-04-18 06:27:55 and 0767567

    I can read in the file and print the whole line but am unsure how to pick out the relevant info in that line

    Any help would be appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Paris area, France
    Rep Power
    You could use a regex or the split function (there are other ways).

    Fot the date at the beginning (assuming you line is in the $line variable):

    Perl Code:
    my $date = substr $line, 0, 19;

    For the numbers, assuming it is always 7 digit long:

    Perl Code:
    my $number = $1 if $line =~ /(\d{7})/;

IMN logo majestic logo threadwatch logo seochat tools logo