help: newbie extracting lines from large file.

Discussion in 'Perl Misc' started by Super-User, Apr 17, 2006.

  1. Super-User

    Super-User Guest

    i am trying to parse a something similar to this format.
    the staring line can be starting at any hour(line1)and last line can be
    any hour.
    when the day changes to the next day. the hour changes to 00 (line 12)

    how can i extract the first 11 lines
    (17:00 -> 23:38)
    then
    (00:01 -> 23:38)
    and so on and so on into individual files until end of the file

    basically i want to create a file for each 24 hours. the only
    thing consistent is the first 00 for each day.
    from the first occurrence of this /\[\d\] \[00:/
    till the line before its next occurrence and also extract
    the top portion (no 00 to start with) into seperate files.

    [1] [17:00:00.234234] blan blah blah
    [2] [17:30:00.234234] blan blah blah
    [1] [17:34:00.234234] blan blah blah
    [1] [18:00:00.234234] blan blah blah
    [2] [19:30:00.234234] blan blah blah
    [1] [20:34:00.234234] blan blah blah
    [1] [21:00:00.234234] blan blah blah
    [2] [22:30:00.234234] blan blah blah
    [1] [23:25:00.234234] blan blah blah
    [1] [23:34:00.234234] blan blah blah
    [1] [23:38:00.234234] blan blah blah
    [1] [00:01:00.234234] blan blah blah
    [1] [00:04:00.234234] blan blah blah
    [1] [00:08:00.234234] blan blah blah
    [1] [03:59:00.234234] blan blah blah
    [1] [05:24:00.234234] blan blah blah
    [1] [09:38:00.234234] blan blah blah
    [1] [17:00:00.234234] blan blah blah
    [2] [17:30:00.234234] blan blah blah
    [1] [17:34:00.234234] blan blah blah
    [1] [18:00:00.234234] blan blah blah
    [2] [19:30:00.234234] blan blah blah
    [1] [20:34:00.234234] blan blah blah
    [1] [21:00:00.234234] blan blah blah
    [2] [22:30:00.234234] blan blah blah
    [1] [23:25:00.234234] blan blah blah
    [1] [23:34:00.234234] blan blah blah
    [1] [23:38:00.234234] blan blah blah
    [1] [00:01:00.234234] blan blah blah
    [1] [00:04:00.234234] blan blah blah
    [1] [00:08:00.234234] blan blah blah
    [1] [03:59:00.234234] blan blah blah
    [1] [05:24:00.234234] blan blah blah
    [1] [09:38:00.234234] blan blah blah


    all help is appreciated and thanks for looking.

    thanks.
     
    Super-User, Apr 17, 2006
    #1
    1. Advertising

  2. Super-User

    Guest

    Super-User <> wrote:
    > i am trying to parse a something similar to this format.
    > the staring line can be starting at any hour(line1)and last line can be
    > any hour.
    > when the day changes to the next day. the hour changes to 00 (line 12)
    >
    > how can i extract the first 11 lines
    > (17:00 -> 23:38)
    > then
    > (00:01 -> 23:38)
    > and so on and so on into individual files until end of the file
    >
    > basically i want to create a file for each 24 hours.


    my $fh;
    my $last_hour;
    while (<>) {
    my $hour=parse_hour($_);
    if (!defined $last_hour or $hour < $last_hour) {
    open $fh, next_file_name() or die $!;
    $last_hour=$hour;
    };
    print $fh $_;
    };


    > the only
    > thing consistent is the first 00 for each day.
    > from the first occurrence of this /\[\d\] \[00:/
    > till the line before its next occurrence and also extract
    > the top portion (no 00 to start with) into seperate files.


    What if there are no entries during the midnight hour, so it goes from
    11 to 01?

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Apr 17, 2006
    #2
    1. Advertising

  3. Super-User

    Super-User Guest

    First..... Thank you. I will be looking at what you gave first thing in
    the morning

    > What if there are no entries during the midnight hour, so it goes from
    > 11 to 01?

    for past seven years... It has never happened.
    there is always 00:XX:XX and there are 200+ events on that hour.
    if it does happen then there are serious implications for the business

    thanks again.

    >
    > Xho
    >
     
    Super-User, Apr 18, 2006
    #3
  4. Super-User

    Denver Guest

    Super-User wrote:
    > Xho wrote:
    >> What if there are no entries during the midnight hour, so it goes from
    >> 11 to 01?

    > for past seven years... It has never happened.


    A lot of things happen only once every 14 years.


    > there is always 00:XX:XX and there are 200+ events on that hour.
    > if it does happen then there are serious implications for the business


    Including that software will crash. :(
    Xho is right just to look for the hour changing to any lower value.
    That gives you a window of more than 22 hours in which unexpected outages won't break your program.

    Do it the safe way as Xho suggested. There is no reason to leave it to chance.
     
    Denver, Apr 18, 2006
    #4
  5. Super-User

    Super-User Guest

    YEP. will do. Thanks.

    Denver wrote:
    > Super-User wrote:
    >
    >> Xho wrote:
    >>
    >>> What if there are no entries during the midnight hour, so it goes from
    >>> 11 to 01?

    >>
    >> for past seven years... It has never happened.

    >
    >
    > A lot of things happen only once every 14 years.
    >
    >
    >> there is always 00:XX:XX and there are 200+ events on that hour.
    >> if it does happen then there are serious implications for the business

    >
    >
    > Including that software will crash. :(
    > Xho is right just to look for the hour changing to any lower value.
    > That gives you a window of more than 22 hours in which unexpected
    > outages won't break your program.
    >
    > Do it the safe way as Xho suggested. There is no reason to leave it to
    > chance.
     
    Super-User, Apr 18, 2006
    #5
  6. Super-User <> wrote:
    > First..... Thank you. I will be looking at what you gave first thing in
    > the morning
    >
    >> What if there are no entries during the midnight hour, so it goes from
    >> 11 to 01?

    > for past seven years... It has never happened.



    So, since you have never been in a car accident in seven years,
    you don't wear your seat belts anymore?


    > if it does happen then there are serious implications for the business



    And one of them will be that this program stops working.

    It would be better if you had one less thing to worry about in such
    trying times.

    An ounce of prevention is worth a pound of cure.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 18, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Wright
    Replies:
    0
    Views:
    556
    Joe Wright
    Jul 27, 2003
  2. Murali
    Replies:
    2
    Views:
    613
    Jerry Coffin
    Mar 9, 2006
  3. Ron Coutts
    Replies:
    0
    Views:
    117
    Ron Coutts
    Dec 15, 2003
  4. Replies:
    4
    Views:
    329
  5. Replies:
    5
    Views:
    119
Loading...

Share This Page