Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > help: newbie extracting lines from large file.

Reply
Thread Tools

help: newbie extracting lines from large file.

 
 
Super-User
Guest
Posts: n/a
 
      04-17-2006
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:3
then
(00:01 -> 23:3
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.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-17-2006
Super-User <(E-Mail Removed)> 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:3
> then
> (00:01 -> 23:3
> 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
 
Reply With Quote
 
 
 
 
Super-User
Guest
Posts: n/a
 
      04-18-2006
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
>

 
Reply With Quote
 
Denver
Guest
Posts: n/a
 
      04-18-2006
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.
 
Reply With Quote
 
Super-User
Guest
Posts: n/a
 
      04-18-2006
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.

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-18-2006
Super-User <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting range of lines tmarc Ruby 2 07-15-2008 11:54 AM
extracting values from consecutive lines baptiste Auguié Ruby 15 10-18-2007 10:12 PM
extracting a range of lines. test Perl 0 04-16-2006 04:45 AM
extracting lines from an address Kris Leech Ruby 8 11-17-2005 10:01 PM
Extracting multiple lines from a file Ron Coutts Ruby 0 12-15-2003 09:14 PM



Advertisments