Monks,
I have a sample script to get the byte offset of a given string from an archive file.
The script reads a large archive file around 200GB and gets the byte offset at which the string was found.
Below is the sample script. This basically reads the archive file, which is a collection of email messages.
These email messages start with string "From " and end with a blank line. The marker here is "From" for every email
my $infil = '20090101.arch';
my $begPat = '^From ';
my $INFILE = new IO::File();
open($INFILE, "< $infil") or die("$infil: $!");
my $Num = 0;
my ($line, $subject);
while(1) {
my $startOffset = tell($INFILE);
$startOffset-=scalar(length($line)) if($line =~ /$begPat/);
while($line = <$INFILE>) {
$subject = $line if($line =~ /^Subject:/);
last;
}
}
close($INFILE);
The syntax of the archive file is as below.
From 10.1.60.40
Accept: */*
Transfer-Encoding: chunked
Subject: Test mail 1
Mime-Version: 1.0
Content-Type: multipart/mixed;
Content-Type: text/plain
xxxxxxxxxxxxx
xxxxxxxxxxxxxxxx
xxxxxxxxxxxx
Content-Type: application/x-gzip
Content-Disposition: attachment; filename="Sampledata.gz"
Content-Transfer-Encoding: base64
H4sIAAAAAAAAA+y9bXOkOLbv+74+BSfiztyeuG0Xz0nWnuu4rqfumq6nXa7qntlxIjIwiW
+1O
From 10.60.128.140
Accept: */*
Transfer-Encoding: chunked
Subject: Test mail 2
Mime-Version: 1.0
Content-Type: multipart/mixed;
Content-Type: text/plain
xxxxxx
xxxxxx
xxxxxx
Basically I want a script do the following
1) Should get the Subject and the byte offsets of every email from the archive(offset of "From " and offset of End of email)
2) The script should be very fast to read the archive files and print out the information
Please suggest the best possible ways to achieve the same. I want the script to complete the processing in the minimum time possible.
Thanks for your time.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.