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
#!/usr/local/bin/perl -w use strict; my $dumpfile = "Proba.txt"; # write the name of the input file my $resdir = "errors"; # directory where will be saved the files with the different error records my %error; #------------------------------------------------------------------------------------------------------------------------------------------------------------------------ open(IN,$dumpfile) || die "Fehler beim Öffnen von $dumpfile: $!\n"; print "Error_Type\tCount\n"; while (<IN>){ chomp($_); if(/([\[]\d+[\]])/){ # find an error number in the input file. format: [0-310] my $number="$1"; $error{$number} += 1; } } close(IN); foreach my $key (sort keys %error){ print $key."\t"."\t".$error{$key}."\n" } #-------------------------------------------------------------------------- if (! -d $resdir) { mkdir($resdir) || die("Could not create result directory $resdir\n"); } foreach my $key (sort keys %error){ open(IN,$dumpfile) || die "Fehler beim Öffnen von $dumpfile: $!\n"; open(OUT, ">$resdir/${dumpfile}_$key.txt"); while (<IN>){ chomp($_); if(/.*[$key]/){ printf OUT ("$_\n"); } } close (OUT); close (IN); }
1
2
3
4
5
6
7
8
9
10
11
d,799,,1,0,,,,,10,1,1,:v:,,04//71;[23]
o,799,,1,0,,,,,12,1,1,:t:,,04//2555;[223]
a,799,,1,0,,,,,10,1,1,:vf:,,07//201;[23]
o,7921,,4,0,,,,,10,1,1,:vt:,,04//331;[0]
k,799,,1,0,,,,,16,1,1,:hh:,,0/201;[2]
o,792,,5,0,,,,,10,1,1,:gg:,,00//2441,,[10]
w,7009,,,0,,,,,14,1,1,:we:,,03//201,,[1]
u,799,,0,0,,,,,10,1,1,:tt:,,04//211;[4]
o,769,,1,0,,,,,17,1,1,:ff:,,09//251;[23]
p,7,,66,0,,,,,10,1,1,:ss:,,04//231;[214]
s,83,,1,0,,,,,1,1,1,ht:,,08//2991,,[23]
Guest EmetoCode (perl): (dl )1 2 3 4# ... if(/([\[]\d+[\]])/){ # find an error number in the input file. format: [0-310] # ... if(/.*[$key]/){
if(/.*\[$key\]/){ ... }
if(/(\[\d+\])/){ ... }
1 2 3 4 5
while (my $line = <IN>){ if ($line =~ m|(\[\d+\])|){ $error{$1} += 1; } }
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/local/bin/perl -w use strict; use warnings; my $dumpfile = "Proba.txt"; # write the name of the input file my $resdir = "errors"; # directory where will be saved the files # with the different error records my %error; #------------------------------------------------------------------------------# if (! -d $resdir) { mkdir($resdir) or die("Could not create result directory $resdir\n"); } open (my $in, '<', $dumpfile) or die "Fehler beim Öffnen von $dumpfile: $!\n"; while (my $line = <$in>) { if ( $line =~ m|(\[\d+\])| ) { push @{$error{$1}}, $line; # Trefferzeile sofort im %error-Hash ablegen } } close $in; print "Error_Type\tCount\n"; for my $key (sort keys %error) { print "$key\t" . scalar @{$error{$key}} . "\n"; # Anzahl open(my $out, '>', "$resdir/${dumpfile}_$key.txt") or die $!; print $out join('', @{$error{$key}}); close $out; }
961020,,ddo0n0,07.12.200 19:12.208
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/local/bin/perl -w
use strict;
use warnings;
my $dumpfile = "Data1.txt"; # write the name of the input file
my $boltons = "Data2.txt";
my $resdir = "errors"; # directory where will be saved the files with the unused packs
my %dump_packs;
my @pack;
my $bolt;
my %exist;
my @tmp;
my $i=0;
if (! -d $resdir) {
mkdir($resdir) or die("Could not create result directory $resdir\n");
}
open (my $in, '<', $dumpfile) or die "Could not open $dumpfile: $!\n";
while (<$in>) {
my @tmp=split(/,/, $_, -1);
my $line= $tmp[0];# the number related to the name
push @{$dump_packs{$tmp[2]}}, $line ; # hash: key: name, value: number
}
close $in;
for my $key (sort keys %dump_packs) { # write the name and occurency in a new file
@pack=$key;
open(my $out, '>', "$resdir/ ${dumpfile}_dump.txt") or die $!;
print $out join('', $key); # key and occurency ???
close $out;
}
open (my $in2, '<', $boltons) or die "Could not open $dumpfile: $!\n";
while (<$in2>) { # find the missing dump_packs keys comparing dump_packs keys with the records into Data2.txt
chomp($_);
my $bolt = $_ ;
for ($i = 0; $i <= $#pack; $i++)
{
if($bolt =~ /$pack[$i]/)
{ $exist{$pack[$i]} += 1;} # exist
else
{ $exist{$pack[$i]} += 0;} # not exist
}
for my $key (sort keys %exist){ # write the unexisting names from the Data1.txt with the related numbers in a new error file: packs not in the list
if ($exist{$key}==0){
my $index=$key;
for my $key (sort keys %dump_packs){
if ($key=~ /$index/){
open(my $out, '>', "$resdir/ ${dumpfile}_packs_notlist.txt") or die $!; {
print $out join(',', @{$dump_packs{$key}});
close $out;
}
}
}
}
}
}
close $in2;
1 2 3 4 5 6
while (<$in>) { my @tmp = split ','; # perldoc -f split my ($number, $name) = @tmp[0,2]; # perldata, Stichwort 'slice' next if ! defined $name; push @{$dump_packs{$name}}, $number ; # key: name, value: number array (!) }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
for my $key (sort keys %dump_packs) { # write the name and occurency in a new file #-> @pack = $key; # FALSCH: @pack enthält nur den Wert $key # besser: my @pack = @{$dump_packs{$key}}; #-> open(my $out, '>', "$resdir/ ${dumpfile}_dump.txt") or die $!; # ^ Leerzeichen im Pfad # File im Append-Modus (!) öffnen open(my $out, '>>', "$resdir/${dumpfile}_dump.txt") or die $!; #-> print $out join('', $key); # key and occurency ??? print $out $key . "," . scalar(@pack) . "\n"; # Name, Anzahl close $out; }
next if ! defined $name;
next if ! defined $name;
1 2 3 4
# wenn $name keinen gültigen Wert beinhaltet, gehe wieder zur Schleife if (not defined($name)) { next; }
Guest EmetoDie Idee das Skript ist eine Datei zu lesen, und die Namen und die Nummer von den Records zu finden. Danach brauche ich eine separarte Datei mit den Namen und der Häufigkeit.
1 2 3 4 5 6
while (<$in>) { my @tmp = split ','; # perldoc -f split my ($number, $name) = @tmp[0,2]; # perldata, Stichwort 'slice' next if ! defined $name; push @{$dump_packs{$name}}, $number ; # key: name, value: number array (!) }
Guest EmetoDanach soll ich die Namen von Datei1 mit einer Liste mit allen richtigen Namen vergleichen und diese Namen und dazugehörige Nummer in einem neuen Error- Datei schreiben, die NICHT in der Liste sind, aber in Datei1 auftauchen. Diese Namen sind falsch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
my $richtige; { local $/; # perldoc perlvar open(my $in2, '<', $boltons) or die $!; $richtige = <$in2>; # gesamte Datei in Skalar speichern close $in2; } open(my $out, '>', "$resdir/${dumpfile}_packs_notlist.txt") or die $!; for my $name (sort keys %dump_packs) { if ($richtige !~ /$name/) { print $out join(',', $name, @{$dump_packs{$name}}) . "\n"; } } close $out;
open (my $in2, '<', $boltons) or die "Could not open $dumpfile: $!\n";
1
2
3
4
961000,,dho2n0,07.12.200 19:12.208
961010,,ddo0f0,07.12.200 19:12.208
961020,,zdo0n0,07.12.200 19:12.208
961020,,t:v,07.12.200 19:12.208
1
2
3
4
5
6
7
my $richtige;
{
local $/; # perldoc perlvar
open(my $in2, '<', $boltons) or die $!;
$richtige = <$in2>; # gesamte Datei in Skalar speichern
close $in2;
}
local $/;