awk '{x[$0]+=1};END{for(i in x){if(x[i]==1)print i}}'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl use strict; use warnings; my $file1='file1.txt'; my $file2='file2.txt'; my %lines; open(my $fh, '<', $file1) or die("ERROR open $file1 $!\n"); while(my $line=<$fh>) { $lines{$line}=1; } close($fh); open(my $fh, '<', $file2) or die("ERROR open $file2 $!\n"); while(my $line=<$fh>) { print "$line" if($lines{$line}); } close($fh);
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
#!/usr/bin/perl use strict; use warnings; my $file1='file1.txt'; my $file2='file2.txt'; # variablen einmal erzeugen # das spart ein wenig Zeit in den den Schleifen my @index; my $line1=''; my $line2=''; my $i=0; my $ii=0; open(my $fh1, '<', $file1) or die("ERROR open $file1 $!\n"); # erstelle Index der Zeilen-Positionen push(@index,tell($fh1)); while($line1=<$fh1>) { chomp($line1); next if($line!~/\S/); push(@index,tell($fh1)); } # entferne Doppelte Zeilen in @index for($i=0; $i++; $i<=$#index ) { seek($fh1,$index[$i],0); $line1=<$fh1>; chomp($line1); for($ii=$#index; $ii--; $ii>$i ) { seek($fh1,$index[$ii],0); $line2=<$fh1>; chomp($line2); splice(@line,$ii,1) if($line1 eq $line2); } } open(my $fh2, '<', $file2) or die("ERROR open $file2 $!\n"); # gehe zweite Datei durch und vergleiche die Zeilen while($line1=<$fh2>) { chomp($line1); next if($line1!~/\S/); for($i=0; $i++; $i<=$#index ) { seek($fh1,$index[$i],0); $line2=<$fh2>; chomp($line2); if($line1 eq $line2) { splice(@line,$i,1); print "$line2\n"; last; } } } close($fh2); close($fh1);