If using perl is an option, here is a small script that does the job for one file, it merely reads reference and input file, tries to substitute reference pattern with empty string. If size is changed, writes to out file. Call it with reference and input filenames as command line arguments.
#!/bin/perl
sub readfile {
my ($filename) = @_;
my $content;
open(my $fh, '<', $filename) or die "cannot open file $filename"; {
local $/;
$content = <$fh>;
}
close($fh);
return $content;
}
sub writefile {
my ($filename, $content) = @_;
open(my $fh, '>', $filename) or die "cannot open file for writing: $filename"; {
print $fh $content;
}
close($fh);
}
my $txtref = readfile($ARGV[0]);
my $txtin = readfile($ARGV[1]);
my $txtout = $txtin;
$txtout =~ s/$txtref//g;
if (length($txtin) ne length($txtout)) {
print STDOUT "changes, length ".length($txtin)." => ".length($txtout)."\n";
my $outf = $ARGV[1].".out";
writefile($outf, $txtout);
} else {
print STDOUT "no changes\n";
}
Just insert the call in a shell loop using find - for example - to operate on directory contents.
Reference
file at any posiition, and if so, then delete the entire file. – Porcupine Sep 23 '18 at 10:27