Thread 2 Dateien vergleichen aber....
(14 answers)
Opened by FDX at 2013-08-13 16:47
Verändert sich leider nichts.
Code (perl): (dl
)
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 #!/usr/bin/perl use strict; use warnings; my $in_file = "datei1.txt"; my $in_file2 = "datei2.txt"; my $gold_standard = "Ausgabe.txt"; open(my $fhone, "<",$in_file) or die $!; open(my $fhtwo, "<",$in_file2) or die $!; open(my $fhout, ">",$gold_standard) or die $!; my %hash = (); my @attributes1 = (); my @attributes2 = (); while (my $line2 = <$fhtwo>) { my ($key,@attributes2) = split (/\s+/,$line2); $hash{$key} = [@attributes2]; } close $fhtwo; while (my $line1 = <$fhone>) { chomp $line1; my ($key,@attributes1) = split (/\s+/,$line1); my $attrib_ref2 = $hash{key}; # Hash um Attribute die in File2 vorkamen aus der Attribut-Liste in File1 rauszufiltern my %filter_attrib = map {$_ => 1} @$attrib_ref2; # Zeile mit Key, Attribute aus File2, gefilterte Attribute aus File1 ausgeben print $fhout join(' ',$key,@$attrib_ref2,grep {!$filter_attrib{$_}} @attributes1)."\n"; } close $fhone; close $fhout; Last edited: 2013-08-14 13:40:14 +0200 (CEST) |