To grep a file within a time range using PERL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hassan470
    New Member
    • Nov 2007
    • 3

    To grep a file within a time range using PERL

    I work in an investment bank. We have a huge log file which contains FIX messages. I have a problem to grep FIX messages within a time rage (i.e. between 9:30 am to 11 pm, those were sent by CITIBANK for ticker symbol MSFT). I tried different ways but it did not work. Could anyone please help me?

    Here is one of the codes in perl:

    [CODE=perl]#!/usr/bin/perl –w

    $myfile = “/tmp/fixlog.txt”;
    open(FH, $myfile) || die “Can not open”;
    while<FH>{
    chomp;
    print “$_\n” if (m/CITIBANK/ | /MSFT/ | /20071115-09:30:00 ~ 20071115-11:00:00/);
    close(FH);[/CODE]

    Here is a code in grep:

    [CODE=perl] grep ‘/CITIBANK/’ | ‘/MSFT/’ | ‘/20071115-09:30:00 ~ 20071115-11:00:00/’ fixlog[/CODE]
    Last edited by eWish; Nov 16 '07, 08:39 PM. Reason: Added Code Tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Your grep code is not perl. How is the data file formatted?

    Comment

    • hassan470
      New Member
      • Nov 2007
      • 3

      #3
      Originally posted by KevinADC
      Your grep code is not perl. How is the data file formatted?
      My grep code is unix command line code.

      The data file is raw log file. (FIX messages).
      Exactly like this:
      8=FIX.4.29=74 35=A49=AXESNET 56=ATLAFM34=1 43=N97=N52=2 0071101-06:01:3798=01 08=6010=237AT LAFM AXESNET 0  _ 8=FIX.4.29=73 35=049=AXESNET 56=ATLAFM34=2 43=N97=N52=2 0071101-06:01:37112=07 013610=195ATL AFM AXESNET 0  T 8=FIX.4.29=62 35=049=AXESNET 56=ATLAFM34=3 43=N97=N52=2 0071101-06:02:3810=193 ATLAFM

      Comment

      • NexisPerl
        New Member
        • Nov 2007
        • 3

        #4
        Can you provide the line you want to match so that someone can provide you with the regex you can use

        Comment

        • hassan470
          New Member
          • Nov 2007
          • 3

          #5
          Originally posted by NexisPerl
          Can you provide the line you want to match so that someone can provide you with the regex you can use
          I need to get the part of the log file within the following time range using regular expression:

          (/20071115-09:30:00 ~ 20071115-11:00:00/);

          Comment

          Working...