I am using the sort cmp method of sorting, but it fails in that the 2 files don't come together. In my logs (simplified, only showing date/time), I see:Tue Oct 16 17:48:03 2018
EDIT EDIT EDIT EDIT EDIT[file1] TIMESTAMP=Wed Oct 5 04:08:28 2018... ... [file1] TIMESTAMP=Fri Nov 2 14:11:28 2018... [file2] TIMESTAMP=Tue Oct 16 17:10:00 2018... ... [file2] TIMESTAMP=Fri Nov 2 14:11:03 2018...
The server/script sees each line as individual lines with newline between them...<13>{Mangled Date/Time} <source>[pid]: TIMESTAMP={I'm using this timestamp} MSGCLS= Title= Severity= message = <message part a> <message part b> ... Message Id= END OF REPORT
Anyone have any ideas? I would appreciate the help!!foreach my $log (@CommonLogFiles) { print "Now Processing $log....\n"; open LOG, "$datadir/$log" or die "LOG $log: $!\n"; print "Just opened $datadir/$log...\n"; $linecnt = 0; while (<LOG>) { chomp $_; $linecnt++; if ( $linecnt == "1" ) { $line .= "[$log] "; } $line .= $_; push @lines, "$line\n"; #print "Just added " . $line . " to the lines array...\n"; $line = ""; $linecnt = 0; } close LOG; } print APPLOG "Files parsed and data inserted into array for further pr +ocessing...\n"; @sortedlines = sort { ($a =~ /^\<\d+\>\w+\s+\d+:\d+:\d+\s+\w+:TIMESTAM +P\=(\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+).*MSGCLS.*$/m)[0] cmp ($b =~ +/^\<\d+\>\w+\s+\d+:\d+:\d+\s+\w+:TIMESTAMP\=(\w+\s+\w+\s+\d+\s+\d+:\d ++:\d+\s+\d+).*MSGCLS.*$/m)[0] } @lines; print SORTED "@sortedlines\n"; print APPLOG "Log files merged together with events in time order...\n +"; close SORTED;
In reply to Merge 2 or more logs, sort by date & time by ImJustAFriend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |