help: newbie extracting lines from large file.

S

Super-User

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.
 
X

xhoster

Super-User said:
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
 
S

Super-User

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.
 
D

Denver

Super-User said:
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.
 
S

Super-User

YEP. will do. Thanks.
A lot of things happen only once every 14 years.




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.
 
T

Tad McClellan

Super-User said:
First..... Thank you. I will be looking at what you gave first thing in
the morning

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top