Hi, Can you please help me in optimizing the code given below. The code below iterates through a single log file of size 3 GB which has got many lines containing any one of the businesses specified in the Array. When it iterates with the first business against the Log file, it picks up the line contaning that particular business and writes it into a new file named after the name of the Business. Basically i will be using the consolidated business files to calculate the number of hits on each site.

Code :
#!/usr/bin/perl #!/usr/bin/perl @businesses = ( ["\"corp.home.ge.com\"","new_corp_home_ge_com.log"], ["\"scotland.gcf.home.ge.com\"","new_scotland_gcf_hom +e_ge_com.log"], ["\"marketing.ge.com\"","new_marketing_ge_com.log"] + ); $rows = scalar(@businesses); #---------------Code to get todays date ------------------------------ +--------- $today = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tod +ay); $year += 1900; $mon++; if ($mday <10) { $mday = "0$mday"; } if ($mon<10) { $mon = "0$mon"; } $today = $year . $mon . $mday; #---------------Code to get yesterdays date -------------------------- +------------- $yesterday = time() - ( 24 * 60 * 60 ); ($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) = local +time($yesterday); $year1 += 1900; $mon1++; if ($mday1 <10) { $mday1 = "0$mday1"; } if ($mon1<10) { $mon1 = "0$mon1"; } $yesterday = $year1 . $mon1 . $mday1; #--------------------------------------------------------------------- +---------- $outfile="consolidatedlog.txt"; open (OUT,">$outfile") or die ("Cud not open the $outfile"); opendir(DIR, "/inside29/urchin/test/logfiles") or die ("couldn't open +igelogs"); while ( defined ($filename = readdir(DIR)) ) { $index = index($filename,$yesterday); if ($index > -1) { $date1 = localtime(); print "The log $filename started at $date1.\n"; open(OLD,"/inside29/urchin/test/logfiles/$filename") || die ("Cud no +t open the $filename"); while (<OLD>) { print OUT $_; } close OLD; $date = localtime(); print "The log $filename ended at $date.\n"; } } closedir (DIR); close OUT; #------------------------------------------------------------- $ct = 0; while ($ct < $rows) { $outfile1 = "/inside29/urchin/test/newfeed/$today-$businesses[$ct][1]" +; $newigebusiness = "$businesses[$ct][0]"; $date2 = localtime(); print "$ct log started for $newigebusiness at $date2\n"; open(OUT,">>$outfile1") || die("Could not open out file!$outfile1"); open(OLD,"consolidatedlog.txt") || die ("Could not open the consolidat +ed file"); while ( <OLD>) { if ((index($_,$newigebusiness))> -1) { print OUT $_; } } close OLD; close OUT; $date3 = localtime(); print "$ct log created for $newigebusiness at $date3\n"; $ct += 1; }

End of Code.
Sample Log file :

Line 1:
16/Jan/2005:00:00:40 -0500 "GET /ge/ige/1/1/4/common/cms_portletview2.html HTTP/1.1" 200 1702 0 "http://erc.home.ge.com/portal/site/insurance/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "erc.home.ge.com"

Line 2:
16/Jan/2005:00:00:40 -0500 "GET /portal/site/transportation/menuitem.8c65c5d7b286411eb198ed10b424aa30/ HTTP/1.1" 200 7596 0 "http://geae.home.ge.com/portal/site/transportation/" "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)" "-" "geae.home.ge.com"

Line 3:
16/Jan/2005:00:00:41 -0500 "GET /ge/ige/26/83/409/common/cms_portletview.html HTTP/1.1" 200 7240 0 "http://erc.home.ge.com/portal/site/insurance/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" "-" "erc.home.ge.com"

Around a millon line will be there in the Log file

Please help.

Thanks

In reply to Reduce the time taken for Huge Log files by pr19939

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.