Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Save 2 files' diff as 3rd file

by Zaxo (Archbishop)
on Mar 03, 2002 at 18:37 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-16 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found