1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @excel_rows; # 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 = <DATA> ) { my @found = $block =~ m{ ^ 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 = ( TYPE => $found[0], RFORM => $found[1], 'REC-SIZE' => $found[2], CREATION => $found[3], 'LAST-RD' => $found[4], STATE => $found[5], EXEC_COPIES => $found[6], 'DATA-BEGIN' => $found[7], 'DATA-END' => $found[8], RELEASE => $found[9], ); push @excel_rows, \%info; } print Dumper \@excel_rows; __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
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
$VAR1 = [
{
'RFORM' => 'FIX',
'RELEASE' => '2013-07-05 12:56:52',
'TYPE' => 'SAM',
'LAST-RD' => '2013-07-05 12:56:17',
'DATA-BEGIN' => '2013-07-05 12:05:10',
'DATA-END' => '2013-07-05 12:23:48',
'REC-SIZE' => '8192',
'STATE' => 'READY',
'EXEC_COPIES' => '2',
'CREATION' => '2010-05-13 00:37:32'
},
{
'RFORM' => 'FIX',
'RELEASE' => '2013-07-06 12:58:52',
'TYPE' => 'SAM',
'LAST-RD' => '2013-07-06 12:56:17',
'DATA-BEGIN' => '2013-07-06 12:06:10',
'DATA-END' => '2013-07-06 12:26:48',
'REC-SIZE' => '8200',
'STATE' => 'READY',
'EXEC_COPIES' => '3',
'CREATION' => '2010-05-12 00:37:32'
}
];
1 2 3 4 5 6 7 8 9 10 11 12 13 14
open my $tsvFH, ">", "out.tsv"; my @header = qw (TYPE RFORM REC-SIZE CREATION LAST-RD STATE EXEC_COPIES DATA-BEGIN DAT-END RELEASE); print $tsvFH $_ . "\t" for @header; print $tsvFH "\n"; for my $row (@excel_rows) { print $tsvFH $row->{$_} ? $row->{$_} . "\t" : "\t" for @header; print $tsvFH "\n"; }
2013-07-15T10:01:01 payxHallo perle,
Hashes sind in Perl per default ungeordnet. Du kannst also nie davon ausgehen, dass Dir ein Hash die key-value-Paare in einer bestimmten Reihenfolge zurückliefert (vor allem nicht in der Reihenfolge, in der Du sie erfasst hast).
2013-07-15T10:01:01 payx...möglicherweise genügt Dir das.
1
2
3
4
^ 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
1
2
3
4
^ 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{19}) \s+ # found-end (Datum oder 19 Leerzeichen)
([^\n]*) \s+ # release