#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @excel_rows; my @header = qw (LISTFILE TYPE RFORM REC-SIZE CREATION LAST-RD STATE EXEC_COPIES DATA-BEGIN DAT-END RELEASE); # blockweises einlesen und nicht zeilenweise # ein block endet mit "ENDJOB" local $/ = "ENDJOB\n"; # einlesen der daten, hier aus __DATA__. Dies auf # das Einlesen einer Datei zu übertragen bleibt dem geneigen # Leser überlassen while ( my $block = ) { my @found = $block =~ m{ ^ LISTFILE:DIRECTORY\sNAME=MAX:\\TEST\.(\d+); .*? ^ TYPE \s+ RFORM \s+ REC-SIZE \s+ # finde die Zeile (\w+) \s+ (\w+) \s+ (\d+) .*? # erste gruppe ist type # zweite gruppe ist RFORM # dritte gruppe ist REC-SIZE ^ CREATION \s+ LAST-RD \s+ (\d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2}) \s+ # creation (\d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2}) \s+ # last-rd .*? ^ STATE \s+ EXEC_COPIES \s+ (\w+) \s+ (\d+) .*? ^ DATA-BEGIN \s+ DATA-END \s+ RELEASE \s+ (\d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2}) \s+ # found-begin (\d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2}) \s+ # found-end (\d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2}) \s+ # release }xms; my %info; for my $i (0..$#header) { $info{$header[$i]} = $found[$i]; } push @excel_rows, \%info; } #print Dumper \@excel_rows; open my $tsvFH, ">", "out.tsv"; #print $tsvFH $_ . "\t" for @header; print $tsvFH join "\t", @header; print $tsvFH "\n"; for my $row (@excel_rows) { #print $tsvFH $row->{$_} ? $row->{$_} . "\t" : "\t" for @header; print $tsvFH join "\t", map { $row->{$_} } @header; print $tsvFH "\n"; } __DATA__ LISTFILE:DIRECTORY NAME=MAX:\TEST.0001; STARTED STARTING TIME 2013-07-05 21:24:01 USER MACHINE4/HEIMO 220: SERVICE READY FOR NEW USER. SUPI 230: USER LOGGED IN, PROCEED. SUPI TYPE RFORM REC-SIZE SAM FIX 8192 CREATION LAST-RD 2010-05-13 00:37:32 2013-07-05 12:56:17 STATE EXEC_COPIES READY 2 DATA-BEGIN DATA-END RELEASE 2013-07-05 12:05:10 2013-07-05 12:23:48 2013-07-05 12:56:52 ENDJOB LISTFILE:DIRECTORY NAME=MAX:\TEST.0001; STARTED STARTING TIME 2013-07-05 21:24:01 USER MACHINE4/HEIMO 220: SERVICE READY FOR NEW USER. SUPI 230: USER LOGGED IN, PROCEED. SUPI TYPE RFORM REC-SIZE SAM FIX 8200 CREATION LAST-RD 2010-05-12 00:37:32 2013-07-06 12:56:17 STATE EXEC_COPIES READY 3 DATA-BEGIN DATA-END RELEASE 2013-07-06 12:06:10 2013-07-06 12:26:48 2013-07-06 12:58:52 ENDJOB