Commit f40f17b
xxwhirlpool
·
2026-07-23 20:38:21 -0400 EDT
parent 7c2516f
add dates2logs.pl from bin repo
1 files changed,
+51,
-0
+51,
-0
1@@ -0,0 +1,51 @@
2+#!/usr/bin/env perl
3+#
4+# borrowed a lot from this post & script:
5+#
6+# https://jfr.im/blog/2024/03/rewriting-irc-log-timestamps/
7+# https://jfr.im/git/archive/rewrite-logs.git/tree/rewrite-logs.pl?h=main
8+
9+use 5.38.2;
10+use strict;
11+use warnings;
12+
13+use File::Basename;
14+use File::Find;
15+use File::Temp qw(tempfile);
16+use File::Copy;
17+
18+# find all logs recursively
19+my $dir = "/home/kat/.irc_history/logs";
20+my @logs; # create log array, empty for now
21+my @findlogs = find(\&wanted, $dir); # this adds everything to @logs i think
22+
23+sub wanted {
24+ return unless -f;
25+ push @logs, $File::Find::name; # add filenames with paths to @logs
26+}
27+
28+foreach my $log (@logs) {
29+ my ($fn, $dir, $ext) = fileparse($log, ".log");
30+
31+ my ($outfh, $outfn) = tempfile();
32+
33+ open(my $fh, "<", "$log") or die("could not open $log: $!");
34+ while (my $line = <$fh>) {
35+ # BRENNAN HELPED HERE TY BRENNAN
36+ # Only match lines with a bare time like "[12:55:02]"
37+ # the old format missing a date.
38+ # e.g. "[2026-01-01 12:55:02]", won't match
39+ # this because right after "["
40+ # it sees "20", not two digits followed by a ":".
41+ if ($line =~ /^\[\d{2}:\d{2}:\d{2}\]/) {
42+ my $newts = substr($line, 1);
43+ my $newdts = "[$fn $newts";
44+ print $outfh $newdts;
45+ } else {
46+ # do nothing just print what's already there
47+ print $outfh $line;
48+ };
49+ }
50+ close $outfh;
51+ copy($outfn, $log)
52+}