use strict;
use warnings;
use Array::Utils qw(:all);
open(my $fh_m, '<', 'master.txt') or
die "Не смог открыть файл :(";
open(my $fh_f, '<', 'file.txt') or
die "Не смог открыть файл :(";
open(my $fh_n, '>', 'new.txt') or
die "Не смог открыть файл :(";
open(my $fh_nm, '>', 'newmaster.txt') or
die "Не смог открыть файл :(";
my @m = map {s/\r?\n?$//r} <$fh_m>;
my @f = map {s/\r?\n?$//r} <$fh_f>;
my @diff = array_minus(@f, @m);
foreach(@m) {
print $fh_nm "$_\n";
}
foreach(@diff) {
print $fh_n "$_\n";
print $fh_nm "$_\n";
}
first = 'master.txt'
second = 'file.txt'
directory = 'C:\\new\\'
A = []
B = []
C = []
D = []
def FileRead(file):
f = open(directory + file , 'r' , encoding = "utf-8")
for i in f:
if q == 0:
A.append(i)
if q == 1:
B.append(i)
f.close()
def FileWrite(file,spisok):
f = open(directory + file , 'w')
for line in spisok:
f.write(line + '\n')
f.close()
for q in range(0,2):
if q == 0:
FileRead(first)
if q == 1:
FileRead(second)
A = [line.rstrip() for line in A]
B = [line.rstrip() for line in B]
for i in A:
if not i in B:
print(i)
C.append(i)
for i in B:
if i in A:
print(i)
C.append(i)
for i in B:
if not i in A:
print(i)
C.append(i)
D.append(i)
FileWrite('newmaster.txt', D)
FileWrite('new.txt',C)