File: splitLog

package info (click to toggle)
r-cran-openmx 2.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,412 kB
  • sloc: cpp: 36,577; ansic: 13,811; fortran: 2,001; sh: 1,440; python: 350; perl: 21; makefile: 5
file content (32 lines) | stat: -rwxr-xr-x 652 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
#
# In OpenMx multithreaded debug output, the current thread is indicated
# by a square bracket block [#] or [#@123] at the beginning of line.

use Modern::Perl '2019';
use Fatal qw(open);

my $logfile = shift @ARGV;

die "Can't find $logfile" if !-e $logfile;

my %Thr;

open(my $fh, $logfile);
my $th = 0;
while (defined(my $l = <$fh>)) {
  if ($l =~ m/^\[(\d+)(\@\d+)?]/) {
    $th = $1;
  }
  push @{$Thr{$th}}, $l;
}

my @parts = split /\./, $logfile;
my $ext = pop @parts;
my $stem = join '.', @parts;

for my $t (sort { $a <=> $b } keys %Thr) {
  my $dest = "$stem$t.$ext";
  open(my $out, ">$dest");
  print $out @{$Thr{$t}};
}