1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#differents between two files
use strict;
use warnings;
use Text::Diff;
use Class::CSV;
open(FILE, ">/home/Documents/Compare/diff.csv") or die "Cannot open file";
my $diffs = diff '/home/Documents/Compare/prtg.csv' => '/home/Documents/Compare/serverliste.csv';
print $diffs;
print FILE "$diffs";
close(FILE);
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
use strict;
use warnings;
use Class::CSV;
my $f1 = "/home/Documents/Compare/prtg.csv";
my $f2 = "/home/Documents/Compare/serverliste.csv";
my $outfile = "/home/Documents/Compare/final_result.csv";
my %results = ();
open FILE1, "$f1" or die "Could not open file:\n";
while(my $line = <FILE1>)
{
$results{$line}=1;
}
close(FILE1);
open FILE2, "$f2" or die "Could not open file:\n";
while(my $line =<FILE2>)
{
$results{$line}++;
}
close(FILE2);
open (OUTFILE, ">$outfile") or die "Cannot open $outfile for writing \n";
foreach my $line (keys %results)
{
print OUTFILE $line if $results{$line} == 1;
}
close OUTFILE;
Guest commanderIch habe zwei unterschiedliche Dateien. Bei diesen Dateien soll der gleiche String ausgegeben werden.
Datei 1:
Aaa
Bbb
Ccc
Datei 2:
Aaa
Bbb
Cdd
Dann wird aaa und bbb ausgegeben. Das funktioniert auch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my %results; open my $fh1, "<", "file1" or die $!; while (my $line = <$fh1>) { chomp $line; $results{ $line } = 1; } open my $fh2, "<", "file2" or die $!; while (my $line = <$fh2>) { chomp $line; my $part = $line; $part =~ s/\..*//; unless ($results{ $part }) { say $line; } }