0601 3 NORM 2 ALLO XLF753 U 0045 0050
0603 5 NORM 2 ALLO ADR2CG 0430 0438
0604 6 NORM 2 ALLO AF681VC i U 0500 0510
0605 7 NORM 2 ALLO AF651PQ i 0515 0523
0606 8 NORM 2 ALLO AF713BR i 0445 0453
0607 9 NORM 2 ALLO AFR100M i 0520 0533
0609 11 NORM 2 ALLO GJT775 i E 2300 2315
0610 12 NORM 2 ALLO AF661WN i 0450 0500
####
0601;3;NORM;2;ALLO;XLF753;U;0045;0050;
0603;5;NORM;2;ALLO;ADR2CG;;0430;0438;
0604;6;NORM;2;ALLO;AF681VC;i U;0500;0510;
0605;7;NORM;2;ALLO;AF651PQ;i;0515;0523;
0606;8;NORM;2;ALLO;AF713BR;i;0445;0453;
0607;9;NORM;2;ALLO;AFR100M;i;0520;0533;
0609;11;NORM;2;ALLO;GJT775;i E;2300;2315;
0610;12;NORM;2;ALLO;AF661WN;i;0450;0500;
####
#!/usr/bin/perl
use strict;
use warnings;
# this is the file we wish to have in a good format
my $file = "$ARGV[0]";
my $Current_Dir = `pwd`;
# print STDOUT "the current directory is $Current_Dir";
open(INFILE,"$ARGV[0]") or die "Can't open $ARGV[0]: $!";
# name of the OUTFILE
# do not forget the "" if
# never put a \n at the end of the OUTFILE name otherwise it does not create the output
my ${outfile_name} = "bon_format_$file";
# to open the file
# OUTFILE is the name of the HANDLE in this case
open (OUTFILE, ">${outfile_name}.csv") or die "Can't open ${outfile_name}.csv: $!";
my @Parts;
my $part;
while () {
# the lines are composed of elements separated by a point comma
my $Line = $_;
my @Elements = split(";", $Line);
my $element = $Elements[1];
@Parts = split(" ",$element);
print STDOUT "le septième élément est $Parts[6]\n";
my $longueur = @Parts;
print STDOUT "le nombre d'éléments est $longueur\n";
# case where $Parts[5] is ADR2G and $Parts[6] is 2045
if (($Parts[5] eq /\w+\d+/) & ($Parts[6] eq /\d\d\d\d/)){
print OUTFILE "$Parts[5];$Parts[6]\n";
}
# case where $Parts[6] is E and $Parts[7] is 6043
if (($Parts[6] eq /\w/) & ($Parts[7] eq /\d\d\d\d/)){
print OUTFILE "$Parts[6];$Parts[7]\n";
}
# case where $Parts[6] is i, $Parts[7] is E and $Parts[8] is 6043
if (($Parts[6] eq /\w/) & ($Parts[7] eq /\w/) & ($Parts[8] eq /\d\d\d\d/)){
print OUTFILE "$Parts[6] $Parts[7];$Parts[8]\n";
}
# case where $Parts[6] is E, $Parts[7] is i, $Parts[8] is U and $Parts[8] is 3065
if (($Parts[6] eq /\w/) & ($Parts[7] eq /\w/) & ($Parts[8] eq /\w/) & ($Parts[9] eq /\d\d\d\d/)){
print OUTFILE "$Parts[6] $Parts[7] $Parts[8];$Parts[9]\n";
}
}
close INFILE;
close OUTFILE;