Author: Gian-Carlo Pascutto
Date: 03:51:29 01/14/01
Hi all,
below is a simple script that allows you to search the CCC
archives easily.
You need:
a) some version of Perl
b) a collection of CCC messages in a series of .dat files
c) paste the program below into a file (e.g. cccsearch) and
make it executable
A simple way to do b is to just unzip the archives into a dir,
then do cat *.txt > ccc.dat.
Usage:
cccsearch MTD lazy eval
Will cause it to search all .dat files in the current dir for
posts that contain 'MTD' and 'lazy' and 'eval'. It will print
out the posts that match, seperated by a line of '-'.
I hope this is usefull for someone...it certainly is for me!
#!/usr/bin/perl -w
%matches = ();
$message = "";
$inmessage = 0;
# loop through all .dat files
while (defined($db = <*.dat>))
{
open (DBF, $db) || die "Couldn't open $db: $!";
while (<DBF>)
{
# Either Date: is the last header field or marks the
# beginning of a secondary header
if (/^Date:\s/)
{
$_ = <DBF>;
$inmessage = 1;
# Secondary header present, skip it
if (/\s+In\sReply\sto:/)
{
while(<DBF>)
{
unless (/^\s+/)
{
$_ = <DBF>;
last;
}
}
}
}
elsif (/^Subject:\s/)
{
$allin = 1;
foreach $word (@ARGV)
{
$allin = 0 unless $matches{$word};
}
if ($allin)
{
print $message;
for ($s = 0; $s <= 80; $s++) {print "-"};
print "\n";
}
$message = "";
$inmessage = 0;
%matches = ();
}
if ($inmessage)
{
foreach $word (@ARGV)
{
if (/$word/i)
{
$matches{$word}++;
}
}
$message .= $_;
}
}
close (DBF);
}
--
GCP
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.