| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Hi,
Thanks a lot Rakesh. it is a chance to have you in this group and that you can have time to help.
Finally I decide to use your perl version below. It works very fine and faster.
And to improve this script, in the result file "/tmp/log/modify_from_2015.log1"
could be put in color only the fields that have been modified.
Thanks for all
Best regards.
-----Message d'origine-----
De : [email protected] [mailto:[email protected]]
Envoyé : samedi 9 janvier 2016 01:59
À : [email protected]
Objet : Re: TR: compare files
........
Here's a perl version for the same:
perl -Mvars='%h,$prev,$ID_COL' -wMstrict -F'/"(?:;")?/' -lane '
BEGIN{
open MODIFY, ">", "/tmp/log/modify_from_2015.log1" or die "$!";
open FRESH, ">", "/tmp/log/new_in_2016.log1" or die "$!";
open REMOVE, ">", "/tmp/log/removed_from_2015.log1" or die "$!";
$ID_COL = 2; --$ID_COL;
}
shift @F;
next if @F < 2;
if ( $. == 1 ) {
# 2015 lines here
$prev = $ARGV;
$h{ $F[$ID_COL] } = $_;
} elsif ( $ARGV ne $prev ) {
# 2016 lines here
if ( ! exists $h{ $F[$ID_COL] } ) {
print FRESH $_;
} elsif( $h{ $F[$ID_COL] } ne $_ ) {
my @F_2015 = split /"(?:;")?/, $h{ $F[$ID_COL] };
shift @F_2015;
my $i=0;
for(@F) {
s/(.*)/\e[31m$1\e[0m/ if $F_2015[$i++] ne $_;
}
print MODIFY q{"} . join(q{";"},@F) . q{"};
delete $h{ $F[$ID_COL] };
} else {
delete $h{ $F[$ID_COL] };
}
} else {
# 2015 lines here
$h{ $F[$ID_COL] } = $_;
}
END{
print REMOVE $_ for values %h;
close MODIFY or die "$!";
close FRESH or die "$!";
close REMOVE or die "$!";
}
' 2015.txt 2016.txt;
HTH
-Rakesh
__________________________
Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing !
Ce message et toutes ses pièces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message.
__________________________