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
|
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
ActiverAccents();
print "Usage : \n\nperl appareillage.pl E:/_DEV/_Fichiers/sortedFile1 E:/_DEV/_Fichiers/sortedFile2\n\n";
my $Date_Heure = date();
print "\nTIME=$Date_Heure\n\n";
my ( $FicA, $FicB ) = @ARGV;
my ( $LigneA, $LigneB ) = "";
my ( $EOFA, $EOFB, $NbA, $NbB ) = 0;
print "\nFICHIERS \n=$ARGV[0]=\n=$ARGV[1]=\n\n";
#Ouverture fichiers lecture 1er enreg
open my $fhA, '<:utf8', $FicA or die "ERROR - $! : $FicA\n";
if ( !($LigneA = <$fhA>)) {
print "Arrêt FICA $FicA vide\n- $!\n";
exit;
}else {
$NbA++;
}
open my $fhB, '<:utf8', $FicB or die "ERROR - $! : $FicB\n";
if ( !($LigneB = <$fhB>)) {
print "Arrêt FICB $FicB vide\n- $!\n";
exit;
} else {
$NbB++;
}
# Appareillage
while ( ! $EOFA || ! $EOFB ) {
if ( $LigneA eq $LigneB ) {
# print "\nExiste dans les deux fichiers :\n";
# print "LIGNEA=$NbA=$LigneA=\n";
# print "LIGNEB=$NbB=$LigneB=\n";
if ( !($LigneA = <$fhA>) ) {
print "=======================================FICA Fini\n\n";
$LigneA = "x{FFFF}";
$EOFA = 1;
} else {
$NbA++;
}
if ( !($LigneB = <$fhB>) ) {
print "=======================================FICB Fini\n\n";
$LigneB = "x{FFFF}";
$EOFB = 1;
} else {
$NbB++;
next if ( $LigneB eq '\n' );
}
} else {
if ( $LigneA lt $LigneB && ! $EOFA ) {
print "\nSuppresion dans FICB :\n";
print "LIGNEA=$NbA=$LigneA=\n";
if ( !($LigneA = <$fhA>) ) {
print "=======================================FICA Fini\n\n";
$LigneA = "x{FFFF}";
$EOFA = 1;
} else {
$NbA++;
}
} else { # $LigneA gt $LigneB
if ( ! $EOFB ) {
print "\nAjout dans FICB :\n";
print "LIGNEB=$NbB=$LigneB=\n";
if ( !($LigneB = <$fhB>) ) {
print "=======================================FICB Fini\n\n";
$LigneB = "x{FFFF}";
$EOFB = 1;
} else {
$NbB++;
}
}
}
}
}
close $fhA;
close $fhB;
$Date_Heure = date();
print "\nTIME=$Date_Heure\n";
exit;
#==============================================================
# Pour avoir les accents sur la console DOS
# http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
#==============================================================
sub ActiverAccents {
my $encodage;
# Windows
if ( lc($^O ) eq 'mswin32') {
eval {
my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
$encodage = "cp$codepage";
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
else {
$encodage = `locale charmap`;
eval {
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
return $encodage;
}
###############
# Date et Heure
sub date {
my $time = shift || time; #$time par defaut vaut le time actuel
my ( $seconde, $minute, $heure, $jour, $mois, $annee, $jour_semaine, $jour_annee, $heure_hiver_ou_ete )
= localtime($time);
$mois += 1;
$annee += 1900;
# On rajoute 0 si le chiffre est compris entre 1 et 9
foreach ( $seconde, $minute, $heure, $jour, $mois, $annee ) { s/^(\d)$/0$1/; }
return "Le $jour/$mois/$annee à $heure:$minute:$seconde";
}
=pod
sort -o sortedFile1 Montaigne_1.txt
sort -o sortedFile2 Montaigne_2.txt |
Partager