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