1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new; open my $csv_file, "<", "DATA.csv" or die "Can't open CSV file: $!\n"; while (my $row = $csv->getline($csv_file)) { my($significator_and_file) = clean($row->[0]); my ($significator, $file) = split /\s+/, $significator_and_file; next unless $significator and $significator eq 'false'; open (my $per_line_fh, ">", "$file.csv" ) or die "Can't open per-line file $file: $!\n"; shift @$row; print $per_line_fh "$file:\n"; for my $i(map {clean($_)} @$row) { my $d = "$i\n"; print $per_line_fh $d if ($i); } close $per_line_fh; } sub clean { my $string = shift; $string =~ /\s*,\s*/; $string =~ s/\s+$//; return $string; }
1
2
3
4
5
6
7
8
9
10
11
12
20150714 00:08:49
false, false, false, false, true, true,
default, ame_a, ame_m, ame_uc, ame_f, ams_l, enced_affi,
true DPA01, fault, fault, fault, fault, fault, 1,
false DPA02, , , , , fault, 1,
false DPA03, fault, fault, olt, fault, fault, 1,
false DPA04, fault, at, fault, 2, fault, 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
_____________DPA02_____________
DPA02
ame_a
ame_m
ame_uc
ame_f
ams_l fault
enced_affi 1
_____________DPA03_____________
DPA03:
ame_a fault
ame_m fault
ame_uc olt
ame_f fault
ams_l fault
enced_affi 1
_____________DPA04_____________
DPA04:
ame_a fault
ame_m at
ame_uc fault
ame_f 2
ams_l fault
enced_affi 1
1
2
3
20150616 22:16:09
default, ame_a, ame_m, ame_uc, ame_f, ams_l, enced_affi,
default, fault, fault, fault, fault, fault, 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
____________DPA02_____________
default: DPA02:
ame_a fault
ame_m fault
ame_uc fault
ame_f fault
ams_l fault fault
enced_affi 1 1
_____________DPA03_____________
default: DPA03:
ame_a fault fault
ame_m fault fault
ame_uc fault olt
ame_f fault fault
ams_l fault fault
enced_affi 1 1
_____________DPA04_____________
default: DPA04:
ame_a fault fault
ame_m fault at
ame_uc fault fault
ame_f fault 2
ams_l fault fault
enced_affi 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
DPA02:
ame_a fault
ame_m fault
ame_uc fault
ame_f fault
ams_l fault fault
enced_affi 1 1
DPA03:
ame_a fault fault
ame_m fault fault
ame_uc fault olt
ame_f fault fault
ams_l fault fault
enced_affi 1 1
DPA04:
ame_a fault fault
ame_m fault at
ame_uc fault fault
ame_f fault 2
ams_l fault fault
enced_affi 1 1