Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Save 2 files' diff as 3rd file

by Zaxo (Archbishop)
on Mar 03, 2002 at 18:37 UTC ( #149004=note: print w/ replies, xml ) Need Help??


in reply to Save 2 files' diff as 3rd file

Here's a version. It's not a general diff, but relies on the error log to contain everything to be rejected. There is dependency on both logs having error messages in the same order. That's reasonable, but may not be guaranteed. If more than one server is logging, there would be a problem.

#!/usr/bin/perl -w # rlog.pl $|++; # stdout hot use strict; # avoid d'oh! bugs require 5; # for following modules my $logDir = '/cygdrive/c/Rsync/logs'; my $allLog = "$logDir/200203021258.all"; my $errLog = "$logDir/200203021258.err"; my $fileLog = "$logDir/200203021258.fil"; # open, but don't slurp open ALL, "< $allLog" or die $!; open ERR, "< $errLog" or die $!; open FLE, "> $fileLog" or die $!; while (<ERR>) { { local $/ = $_; my $diffs = <ALL> || "Alert: '$_' from $errLog not found\n"; chomp $diffs; print FLE $diffs; } } print FLE while <ALL>; close FLE or die $!; close ERR or die $!; close ALL or die $!;
We go through the error log one line at a time. For each line, we look forward in the all-log until we find it, by diamond op and $/ magic. We delete the matched error line with chomp and print to the new log extract file. When done with errors, we tack on the rest of the log. Untested, but it should work.

Update: Added a more graceful failure mode if an error line is missing.

After Compline,
Zaxo


Comment on Re: Save 2 files' diff as 3rd file
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://149004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-07-10 04:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls