|< 1 2 >| | 15 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl -w
use strict;
$/ = qq{"\$"\t""\t""\n};
my $inputfile = 'C:\test.asc';
open A, $inputfile or die "Cannot open '$inputfile': $!";
while ( <A> ) {
my ($file) = /\n.*?"(.*?)"/ or next;
open B, "> $file.csv" or warn( "Cannot open '$file': $!" ), next;
print "[DEBUG] '$file': open ok\n";
chomp $_;
print B $_;
close B or warn( "Cannot close '$file': $!" ), next;
print "[DEBUG] '$file': close ok\n";
}
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
#!/usr/bin/perl
use strict;
use warnings;
my @Buffer = ();
while (<DATA>) {
push @Buffer, $_;
if ($Buffer[-1] =~ /^"\$/) {
if (@Buffer <= 1) {
warn "Korrupte Daten vor Zeile $.";
}
else {
(my $fn = $Buffer[1]) =~ s~^\s*"([^"]+).*$~$1~;
unless (length $fn) {
warn "Kann Dateinamen vor Zeile $. nicht ermitteln.";
}
else {
chomp $fn;
$fn .= '.csv';
open(OUT, ">$fn") or die "Cannot open '$fn': $!";
print "[DEBUG] '$fn': open ok\n";
for my $buf (@Buffer) {
print OUT $buf;
}
close(OUT) or warn "Cannot close '$fn': $!";
print "[DEBUG] '$fn': close ok\n";
}
}
@Buffer = ();
}
}
_ _DATA_ _
"beginn erster Datensatz" "" ""
"matthew01" "" ""
"texttexttexttetx text text" "" ""
"texttext text" "" "98387"
"text, text" "" ""
"text" "" ""
"" "" ""
"text" 0.00 0.00
"$" "" ""
"" "" ""
"matthew02" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.06.1999" ""
"$" "" ""
"" "" ""
"matthew03" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" ""
"" "" ""
"matthew04" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" ""
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
#!/usr/bin/perl
use strict;
use warnings;
my @Buffer = ();
while (<DATA>) {
push @Buffer, $_;
if ($Buffer[-1] =~ /^"\$/) {
if (@Buffer <= 1) {
warn "Korrupte Daten vor Zeile $.";
}
else {
(my $fn = $Buffer[1]) =~ s~^\s*"([^"]+).*$~$1~;
chomp $fn;
unless (length $fn) {
warn "Kann Dateinamen vor Zeile $. nicht ermitteln.";
}
else {
$fn .= '.csv';
open(OUT, ">$fn") or die "Cannot open '$fn': $!";
print "[DEBUG] '$fn': open ok\n";
for my $ind (0..$#Buffer-1) {
print OUT $Buffer[$ind];
}
close(OUT) or warn "Cannot close '$fn': $!";
print "[DEBUG] '$fn': close ok\n";
}
}
@Buffer = ();
}
}
_ _DATA_ _
"beginn erster Datensatz" "" ""
"matthew01" "" ""
"texttexttexttetx text text" "" ""
"texttext text" "" "98387"
"text, text" "" ""
"text" "" ""
"" "" ""
"text" 0.00 0.00
"$" "" ""
"" "" ""
"matthew02" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.06.1999" ""
"$" "" ""
"" "" ""
"matthew03" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" ""
"" "" ""
"matthew04" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" ""
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
#!/usr/bin/perl
use strict;
use warnings;
my $inputfile = 'C:\test.asc';
open A, $inputfile or die "Cannot open '$inputfile': $!";
my @Buffer = ();
while (<A>) {
push @Buffer, $_;
if ($Buffer[-1] =~ /^"\$/) {
if (@Buffer <= 1) {
warn "Korrupte Daten vor Zeile $.";
}
else {
(my $fn = $Buffer[1]) =~ s~^\s*"([^"]+).*$~$1~;
chomp $fn;
unless (length $fn) {
warn "Kann Dateinamen vor Zeile $. nicht ermitteln.";
}
else {
$fn .= '.csv';
open(OUT, ">$fn") or die "Cannot open '$fn': $!";
print "[DEBUG] '$fn': open ok\n";
for my $ind (0..$#Buffer-1) {
print OUT $Buffer[$ind];
}
close(OUT) or warn "Cannot close '$fn': $!";
print "[DEBUG] '$fn': close ok\n";
}
}
@Buffer = ();
}
}
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
#!/usr/bin/perl
use strict;
use warnings;
my @Buffer = ();
my $i = 0;
while(my $line = <DATA>){
$Buffer[$i] .= $line;
$i++ if($line =~ /"\$("\s")+"$/);
if($i == 20){
print2File(\@Buffer);
$i = 0;
@Buffer = ();
}
}
sub print2File{
my ($buffer) = @_;
foreach my $set(@{$buffer}){
my (undef,$name,undef) = split(/\n/,$set,3);
($name) = $name =~ /"([^"]+)/;
$name =~ s/\s/_/g;
open(W_FILE,">$name") or die $!;
print W_FILE $set;
close W_FILE;
}
}
"beginn erster Datensatz" "" ""
"matthew01" "" ""
"texttexttexttetx text text" "" ""
"texttext text" "" "98387"
"text, text" "" ""
"text" "" ""
"" "" ""
"text" 0.00 0.00
"$" "" ""
"" "" ""
"matthew02" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.06.1999" ""
"$" "" ""
"" "" ""
"matthew03" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" ""
"" "" ""
"matthew04" "" ""
"" "" ""
"texttext text" "5330146514" ""
"" "" ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" """ ""
"text, text" "" ""
"" "" ""
"text" "30.08.2000" ""
"$" "" """ ""
(my $fn = $Buffer[1]) =~ s~^\s*"([^"]*).*$~$1~;
|< 1 2 >| | 15 Einträge, 2 Seiten |