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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.