Martien Verbruggen said:
On Tue, 24 Jun 2003 19:27:20 -0700,
I am working with files that grow to a size of 1-2 mb each day
of the month. The file is closed at the end of each month.
The format of the messages is:
snip
It would be better to include _real_ data from your log file, and even
better to show more than one record, so we can see whether there is
anything between records/messages that can be used.
I want to do a search of the files each day for some previous days messages.
The important data in the message to me is the date (YY-MN-DY),
and the MSG1 (actually MSG[1-50]). Some of the messages have data
in every line (MSG1), and some messages have lines that are blank followed
by lines with data. Is there a good, or simple way to gather into a new
file
all of the previous days MSGs that I want? Hope my question makes sense.
Maybe something like (untested):
my $yesterday = "03-06-25"; # assuming that that is the format
open F, "mylogfile" or die $!;
while (<F>)
{
if (/$yesterday.*MSG(\d\d?)/)
{
# We now have the message number in $1
# Since you're only interested in yesterday, you already know
# the date. No need to capture it.
print;
}
}
close F;
I am assuming that none of the other lines have that pattern. I'm also
assuming that the BBBB bits above don't contain anything matching
'MSG\d\d?', or if it foes that it's actually the correct number as
well.
Hard to tell whether this is sufficient. You give us very little
information about what exactly you're having trouble with. next time,
apart from showing real data, also show us what you have tried (real
code), and which bit exactly you're having trouble with.
Below is an example of the data that I was trying to reflect.
There is a CTRL M at end of each line after the line that starts "-----New".
and there is a CTRL Y on the line prior to the line that starts "-----New".
I am new at this obviously, my original approach was to delete the data that
I don't need to try to group the messages into paragraphs:
#!/usr/bin/perl -w
while (<>) {
s/^M|^Y|^-.*//;
print:
}
So... You're removing any initial M or Y, or anything in a line that
initially starts with -?
Then I pipe that to another program:
#!/usr/bin/perl -w
$/ = "";
while (<>) {
print if / 03-06-01 /;
}
And now you print "paragraphs" that contain that date.
Here is some file data:
-----New Message Received on 06-01-2003 at 00:00:03 -----
S21D-685375656 03-06-01 00:00:03 611259 TIME SANF
REPT TIME 03-06-01 00:00:03
Well.. That data doesn't look at all like what you described in your
original post. In your OP, you were talking about being interested in
some message number, and the date only. I don't see any message
number.
Given that ctrl-Y seems to be the record separator, or terminator, I'd
probably set $/ to ctrl-Y, and then process the file message by
message, selecting on whichever criteria you want, and I'm more
confused now about what you do and don't want. I'll just make up
something, and leave it up to you to change it. You're not clear on
whether all of the dates in those messages can be used, or whether it
has to be one in the capitalised bits. I'll simply select on that
first line, because it's easier.
#!/usr/local/bin/perl
use strict;
use warnings;
# Set record separator to ctrl-Y followed by a newline
$/ = "\cY\n";
my $target_date = "06-01-2003";
while (<DATA>)
{
chomp;
# We're only interested in records that contain our target date
next unless /Received on $target_date at/;
# Remove any M or Y following a newline (Just following your code,
# I think)
s/\n(M|Y)/\n/g;
# Remove that first line. We are not interested in it.
s/\A.*--\n//;
# Print what's left
print;
}
__DATA__
-----New Message Received on 06-01-2003 at 00:00:03 -----
S21D-685375656 03-06-01 00:00:03 611259 TIME SANF
REPT TIME 03-06-01 00:00:03
-----New Message Received on 06-01-2003 at 00:00:06 -----
S570-58785830 03-06-01 00:00:06 611262 SLC SANF
* REPT RT SID=2050 DNUSRT=2-0-60 MINOR FAR END EVENT=12489
-----New Message Received on 06-01-2003 at 02:47:03 -----
S570-58785830 03-06-01 02:47:03 612603 MDIIMON SANF
A REPT MDII CVN SIGTYPE ISUP TKGMN 303-4 SZ 168 OOS 0 ID
SUPRVSN TIME 02:47:03 NEN=2-0-0-1-1-4-3-4 TRIAL 1 CARRFLAG NC
OGT NORMAL CALL CALLED-NO 1288 CALLING-NO 9033
DISCARD 0
OPC 123083056 DPC 456041003 CIC 3004
-----New Message Received on 06-01-2003 at 02:53:01 -----
S32C-942407807 03-06-01 02:53:01 612617 MAINT SANF
M REPT AUDSTAT COMPLETED
ROUTINE AUDIT SCHEDULING IS ALLOWED
-----New Message Received on 06-01-2003 at 02:54:01 -----
S570-58785830 03-06-01 02:54:01 612619 TRCE SANF
A TRC IPCT EVENT 2621
DN=9759 TERM=3-H'329f DIALED
DN=5551212
TIME 02:54:01
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|